我有以下代码:
use Phinx\Migration\AbstractMigration;
class CreateNewTableForJobListLanguages extends AbstractMigration
{
/**
* Migrate up.
*/
public function up()
{
$this->execute('
CREATE TABLE `v2_joblist_languages` (
`id` int(11) UNSIGNED NOT NULL AUTO_INCREMENT,
`joblist_id` int(11) NULL,
`language_id` int(11) NULL,
FOREIGN KEY (`joblist_id`) REFERENCES `v2_job_alerts` (`id`),
FOREIGN KEY (`language_id`) REFERENCES `v2_languages` (`id`))
');
}
尝试迁移时,出现以下错误:
SQLSTATE[42000]: Syntax error or access violation: 1075 Incorrect table definition; there can be only one auto column and it must be defined as a key
为了解决这个问题,我的头都碎了,我明白为什么会这样。感谢您的帮助,提前谢谢。
1条答案
按热度按时间oxosxuxt1#
这是一个many:many mapping table?真的有必要吗
id
? 我对此表示怀疑;把它扔掉。同时提供
PRIMARY KEY(joblist_id), language_id), INDEX(language_id, joblist_id)
你真的想把这两列分开吗NULLable
? 我怀疑。更多提示many:many: http://mysql.rjweb.org/doc.php/index_cookbook_mysql#many_to_many_mapping_table