public function up()
{
Schema::create('jadwal_praks', function (Blueprint $table) {
$table->increments('id');
$table->integer('thnajrn_id', 10)->unsigned();
$table->foreign('thnajrn_id')->references('id')->on('tahun_ajarans');
$table->integer('prak_id', 10)->unsigned();
$table->foreign('prak_id')->references('Prak_kode')->on('mata_praks');
$table->integer('hari_id', 10)->unsigned();
$table->foreign('hari_id')->references('id')->on('haris');
$table->integer('jam_id', 10)->unsigned();
$table->foreign('jam_id')->references('id')->on('jams');
$table->integer('ruang_id', 10)->unsigned();
$table->foreign('ruang_id')->references('id')->on('ruangs');
$table->integer('kap_id', 10)->unsigned();
$table->foreign('kap_id')->references('id')->on('kapasitas');
$table->timestamps();
$table->rememberToken();
});
}
运行后 php artisan migrate
[Illuminate \ Database \ QueryException] SQLSTATE [42000]:语法错误或访问冲突:1075表定义不正确;只能有一个自动组合,它必须被定义为键(SQL:create table jadwal_praks(id int unsigned not null auto_increment primary key,thnajrn_id int unsigned not null auto_increment primary key,prak_id int unsigned not null auto _increment primary key ,hari_id int unsigned not null auto_increment主键,jam_id int unsigned not nul l auto_increment主键,ruang_id int unsigned not null auto_increment主键,kap_id int unsigned not null auto_increment主键,created_at timestamp null,updated_at timestamp null,remember_token v archar( 100)null)默认字符集utf8 collate utf8_unicode_ci)
还有这个
[PDOException] SQLSTATE [42000]:语法错误或访问冲突:1075表定义不正确;只能有一个自动列,必须将其定义为键
2 回答
根据我的观察,我会说你应该删除你添加到外国字段的
default
值(例如):至:
希望这可以帮助 :)
当你使用$ table-> integer('thnajrn_id',10) - > unsigned();这意味着您将第二个参数设置为true表示AutoIncrement
使用table-> integer('thnajrn_id') - > length(10) - > unsigned();
https://laracasts.com/discuss/channels/general-discussion/why-am-i-getting-a-database-error-on-migration