[英]MySQL - 1075 Incorrect table definition, there can be only one auto column and it must be defined as a key
I have the following code: 我有以下代码:
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`))
');
}
When trying to migrate, I get the following error: 尝试迁移时,出现以下错误:
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
Broke my head trying to solve it, and understand why is it happening. 试图解决这个问题,让我震惊了,明白为什么会这样。 Grateful for any assistance, thanks in advance.
感谢您的帮助,在此先感谢。
This is a many:many mapping table? 这是一个多对多映射表? Is there really any need for
id
? 真的需要
id
吗? I doubt it; 我对此表示怀疑; get rid of it.
摆脱它。
Also provide PRIMARY KEY(joblist_id), language_id), INDEX(language_id, joblist_id)
还提供
PRIMARY KEY(joblist_id), language_id), INDEX(language_id, joblist_id)
Do you really want the two columns to be NULLable
? 您是否真的希望这两
NULLable
? I doubt it. 我对此表示怀疑。
More tips on many:many: http://mysql.rjweb.org/doc.php/index_cookbook_mysql#many_to_many_mapping_table 关于以下方面的更多技巧:许多: http : //mysql.rjweb.org/doc.php/index_cookbook_mysql#many_to_many_mapping_table
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.