MySQL-1075错误的表格定义,只能有一个自动列,必须将其定义为键

时间:2018-07-25 15:29:13

标签: mysql mariadb

我有以下代码:

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 个答案:

答案 0 :(得分:0)

这是一个多对多映射表?真的需要id吗?我对此表示怀疑;摆脱它。

还提供PRIMARY KEY(joblist_id), language_id), INDEX(language_id, joblist_id)

您是否真的希望这两列为NULLable?我对此表示怀疑。

许多方面的更多提示:许多:http://mysql.rjweb.org/doc.php/index_cookbook_mysql#many_to_many_mapping_table