简体   繁体   中英

String as Primary Key in Laravel migration

I've had to change a table in my database so that the primary key isn't the standard increments .

Here's the migration,

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

However, MySQL keeps returning with,

Syntax error or access violation: 1170 BLOB/TEXT column 'code' used in key specification without a key length (SQL: alter table settings add primary key settings_code_primary ( code )

I've tried leaving the normal increments id in there and modifying the table in a different migration but the same thing happens.

Any ideas of what I'm doing wrong?

Laveral Version 5.4.23

将其更改为字符串。

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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