Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQLSTATE[42000]: Syntax error or access violation: 1064 default character set utf8 collate utf8_unicode_ci' at line 1 [duplicate]

I'm trying to migrate this code into mysql database but keep getting this error message.

SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ') default character set utf8 collate utf8_unicode_ci' at line 1

public function up()
    {
        Schema::create('user', function(Blueprint $table)
        {
            $table->engine = 'InnoDB';
            $table->increments('id');
            $table->string('name');
            $table->string('email')->unique();
            $table->string('password', 60);
            $table->rememberToken();
            $table->timestamps();
            $table->integer('projectId')->unsigned();
            $table->boolean('isStudent');
            $table->boolean('isCompany');
            $table->String('img');
        });

        Schema::create('user', function($table)
        {
            $table->foreign('projectId')->references('id')->on('project');

        });


    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::drop('user');
    }
}
like image 386
Alex Avatar asked Jun 14 '15 06:06

Alex


2 Answers

For the second instance, use Schema::table

For more information, see here: https://stackoverflow.com/a/28007930/938664

public function up()
    {
        Schema::create('user', function(Blueprint $table)
        {
            $table->engine = 'InnoDB';
            $table->increments('id');
            $table->string('name');
            $table->string('email')->unique();
            $table->string('password', 60);
            $table->rememberToken();
            $table->timestamps();
            $table->integer('projectId')->unsigned();
            $table->boolean('isStudent');
            $table->boolean('isCompany');
            $table->string('img');

            $table->foreign('projectId')->references('id')->on('project')->onDelete('cascade');

        });


    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::drop('user');
    }
}
like image 154
Chris Burton Avatar answered Nov 07 '22 07:11

Chris Burton


try this Schema::table

public function up()
{
    Schema::create('user', function(Blueprint $table)
    {
        $table->engine = 'InnoDB';
        $table->increments('id');
        $table->string('name');
        $table->string('email')->unique();
        $table->string('password', 60);
        $table->rememberToken();
        $table->timestamps();
        $table->integer('projectId')->unsigned();
        $table->boolean('isStudent');
        $table->boolean('isCompany');
        $table->String('img');
    });

    Schema::table('user', function($table)
    {
        $table->foreign('projectId')->references('id')->on('project');

    });


}

/**
 * Reverse the migrations.
 *
 * @return void
 */
public function down()
{
    Schema::drop('user');
} }
like image 43
Ivan Markov Avatar answered Nov 07 '22 07:11

Ivan Markov