Laravel - 使用未签名主键的表迁移错误

时间:2016-03-16 14:20:48

标签: php mysql laravel laravel-5.2

目前,我在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'(错误号:150)(SQL:create table   site_permission_modulesid int unsigned not null auto_increment   主键,name var char(255)not null,created_at时间戳   null,updated_at timestamp null)默认字符集utf8 collat​​e   utf8_unicode_ci)

我有很多其他表正在成功而没有任何问题。

当我复制Laravel抛出到MySQL的SQL语句时,它也会失败,但只要删除主键上的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;

有谁知道为什么会这样?

1 个答案:

答案 0 :(得分:0)

结果是答案是MySQL版本太低了,而在MySQL 5.5版本上运行MAMP时,迁移无效。我已经在5.7版本上测试了迁移,并成功运行了所有迁移。

但是,由于我在使用相同版本的MAMP时完成了其他Laravel迁移,这确实让我感到困惑。

这可能是我首先测试的机器上MySQL默认的引擎,不幸的是我现在无法测试它。

相关问题