Raihan 'illiyyin
Raihan 'illiyyin

Reputation: 13

Syntax error or access violation when inserting a record

I am getting the following error:

SQLSTATE[42000]: Syntax error or access violation: 1067 Invalid default value for 'id' (SQL: create table advertising (id bigint unsigned not null default 'None' auto_increment primary key, slug varchar(50) collate 'utf8_unicode_ci' not null after id, provider_name varchar(100) collate 'utf8_unicode_ci' null, tracking_code_large text collate 'utf8_unicode_ci' null, tracking_code_medium text collate 'utf8_unicode_ci' null, tracking_code_small text collate 'utf8_unicode_ci' null, active tinyint unsigned null default '1') default character set utf8 collate 'utf8_unicode_ci')

and this is my code :

public function up()
    {
        Schema::create('advertising',function(Blueprint $table){
            $table->bigIncrements('id')->unsigned()->default('None')->nullable($value = false)->autoIncrement();
            $table->string('slug',50)->after('id')->collation('utf8_unicode_ci')->nullable($value = false);
            $table->string('provider_name',100)->collation('utf8_unicode_ci')->default(null)->nullable($value = true);
            $table->text('tracking_code_large')->collation('utf8_unicode_ci')->default(null)->nullable($value = true);
            $table->text('tracking_code_medium')->collation('utf8_unicode_ci')->default(null)->nullable($value = true);
            $table->text('tracking_code_small')->collation('utf8_unicode_ci')->default(null)->nullable($value = true);
            $table->tinyInteger('active')->unsigned()->nullable($value = true)->default(1);
        });
    }

I try to change value of id but its still get error.

Upvotes: 1

Views: 140

Answers (1)

nakov
nakov

Reputation: 14298

You cannot have a default value for a auto-incremented column, also I don't understand why would you want that to be nullable.

Change this:

$table->bigIncrements('id')->unsigned()->default('None')->nullable($value = false)->autoIncrement();

To just this:

$table->bigIncrements('id');

bigIncrements already means auto incremented and unsigned.

Upvotes: 1

Related Questions