我正在尝试将此代码迁移到mysql数据库,但不断收到此错误消息.
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');
}
}
解决方法:
对于第二个实例,使用Schema :: table
有关更多信息,请参见此处: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');
}
}