繁体   English   中英

Laravel - 带有未签名主键的表迁移错误

[英]Laravel - Table migration crror with unsigned primary key

目前我在 Laravel 中进行了失败的迁移:

public function up()
{
    Schema::create('site_permission_modules', function(Blueprint $table)
    {
        $table->increments('id');
        $table->string('name');
        $table->timestamps();
    });
}

/**
 * Reverse the migrations.
 *
 * @return void
 */
public function down()
{
    Schema::drop('site_permission_modules');
}

显示的错误如下:

SQLSTATE[HY000]: 一般错误: 1005 无法创建表 'orgasystem.site_permission_modules' (errno: 150) (SQL: create table site_permission_modules ( id int unsigned not null auto_increment primary key, name var char(255) not null, created_at时间戳 null, updated_at时间戳 null) 默认字符集 utf8 整理 utf8_unicode_ci)

我有很多其他的表都成功了,没有任何问题。

当我将 Laravel 抛出的 SQL 语句复制到 MySQL 时,它也失败了,但是一旦我删除了主键上的 unsigned 关键字,它就会成功。 请参阅下面的声明。

失败:

create table `site_permission_modules` (
    `id` int unsigned not null auto_increment primary key, 
    `name` varchar(255) not null, 
    `created_at` timestamp null, 
    `updated_at` timestamp null) 
default character set utf8 collate utf8_unicode_ci;

成功:

create table `site_permission_modules` (
    `id` int not null auto_increment primary key, 
    `name` varchar(255) not null, 
    `created_at` timestamp null, 
    `updated_at` timestamp null) 
default character set utf8 collate utf8_unicode_ci;

有谁知道为什么会发生这种情况?

原来答案是 MySQL 版本太低,而在 MySQL 5.5 版上运行 MAMP 时,迁移不起作用。 我已经在 5.7 版上测试了迁移,并且它成功地运行了所有迁移。

然而,这确实让我有点困惑,因为我已经完成了其他 Laravel 迁移,同时仍在使用相同版本的 MAMP。

这可能与 MySQL 在我首先测试的机器上默认使用的引擎有关,不幸的是我目前无法测试它。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM