简体   繁体   中英

An error occur when i am trying to add primary key's data type string using laravel

my code is here

public function up()
    {
        Schema::create('semesters', function (Blueprint $table) {
//            $table->increments('id');
            $table->engine = 'InnoDB';

            $table->string('semester_id')->unique()->unsigned();

            $table->timestamps();

        });
    }

error is here

[Illuminate\\Database\\QueryException] SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'unsigned not null, created_at times tamp default 0 not null, updated_at times' at line 1 (SQL: create table semesters ( semester_id text unsigned not null, created_at timestamp default 0 not null, updated_at timestamp default 0 not null) default character s et utf8 collate utf8_unicode_ci engine = InnoDB)

You mix types: string and unsigned (which is int )

So if you need this column to be a string you should get rid of unsigned part here:

 $table->string('semester_id')->unique()->unsigned(); <---

so that line becomes:

 $table->string('semester_id')->unique(); 

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