簡體   English   中英

字符串作為 Laravel 遷移中的主鍵

[英]String as Primary Key in Laravel migration

我不得不更改數據庫中的一個表,以便primary key不是標准increments

這是遷移,

public function up()
{
    Schema::create('settings', function (Blueprint $table) {
        $table->text('code', 30)->primary();
        $table->timestamps();
        $table->text('name');
        $table->text('comment');
    });
}

然而,MySQL 不斷返回,

語法錯誤或訪問沖突:1170 BLOB/TEXT 列“代碼”在沒有鍵長度的鍵規范中使用(SQL:alter table settings add primary key settings_code_primary ( code )

我嘗試將正常的increments id保留在那里並在不同的遷移中修改表,但同樣的事情發生了。

關於我做錯了什么的任何想法?

Laveral Version 5.4.23

將其更改為字符串。

$table->string('code', 30)->primary();

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM