我试图将此代码迁移到mysql数据库中,但不断收到此错误消息。
SQLSTATE [42000]:语法错误或访问冲突:1064您有 SQL语法错误;查看与您的手册相对应的手册 MySQL服务器版本的正确语法使用接近')默认值 字符集utf8 collate utf8_unicode_ci'在第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');
}
}
答案 0 :(得分:4)
对于第二个实例,请使用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');
}
}
答案 1 :(得分:0)
尝试此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');
} }