添加列外键 MySQL
adding column Foreign key MySQL
我创建了 2 table 并尝试将 FOREIGN KEY 添加到底部图片上的 table。表格看起来像
http://zapodaj.net/02b893dfd5982.png.html
顶部 table 名称:"tabela_postow" 底部名称:"tabfile"
我尝试使用外键将列添加到 tabfile 但总是得到错误代码:1005。无法创建 table 'heroku_fd1c348s48a7d8c.#sql-dd3f_ad2f19'(错误号:150)
我用这个命令。
改变TABLE tabfile
添加列 idpost mediumint(9) 不为空,
添加外键 (idpost) 参考 tabela_postow(id);
我是新手,真的不知道为什么它不起作用。
You can check the status of InnoDB (SHOW ENGINE INNODB STATUS)
The primary key's on the referenced tables most likely should be NOT NULL
所以首先创建 table 其中列 id 应该是这样的 id MEDIUMINT NOT NULL primary key
或者手动创建索引 CREATE INDEX ix_id ON table_name (id)
我创建了 2 table 并尝试将 FOREIGN KEY 添加到底部图片上的 table。表格看起来像
http://zapodaj.net/02b893dfd5982.png.html 顶部 table 名称:"tabela_postow" 底部名称:"tabfile"
我尝试使用外键将列添加到 tabfile 但总是得到错误代码:1005。无法创建 table 'heroku_fd1c348s48a7d8c.#sql-dd3f_ad2f19'(错误号:150)
我用这个命令。
改变TABLE tabfile 添加列 idpost mediumint(9) 不为空, 添加外键 (idpost) 参考 tabela_postow(id);
我是新手,真的不知道为什么它不起作用。
You can check the status of InnoDB (SHOW ENGINE INNODB STATUS)
The primary key's on the referenced tables most likely should be NOT NULL
所以首先创建 table 其中列 id 应该是这样的 id MEDIUMINT NOT NULL primary key
或者手动创建索引 CREATE INDEX ix_id ON table_name (id)