簡體   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