【问题标题】:MySQL - 1075 Incorrect table definition, there can be only one auto column and it must be defined as a keyMySQL - 1075 表定义不正确,只能有一个自动列,必须定义为键
【发布时间】:2019-01-02 11:56:23
【问题描述】:

我有以下代码:

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

我想解决这个问题,并理解它为什么会发生。感谢您的任何帮助,在此先感谢。

【问题讨论】:

标签: mysql mariadb


【解决方案1】:

这是一个多:多映射表?真的需要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

【讨论】:

    猜你喜欢
    • 2013-07-12
    • 2017-05-31
    • 2013-12-17
    • 1970-01-01
    • 2015-11-17
    • 2015-04-05
    • 1970-01-01
    • 1970-01-01
    • 2020-01-01
    相关资源
    最近更新 更多