我的trophies
表:
public function up()
{
Schema::create('trophies', function (Blueprint $table) {
$table->increments('id');
$table->integer('tournament_id')->unsigned()->nullable();
$table->foreign('tournament_id')
->references('id')
->on('tournaments')
->onUpdate('cascade')
->onDelete('cascade')
;
$table->integer('season_id')->unsigned()->nullable();
$table->foreign('season_id')
->references('id')
->on('seasons')
->onUpdate('cascade')
->onDelete('cascade')
;
$table->integer('user_id')->nullable()->unsigned();
$table->foreign('user_id')
->references('id')
->on('users')
->onUpdate('cascade')
->onDelete('cascade');
;
$table->integer('team_id')->nullable()->unsigned();
$table->foreign('team_id')
->references('id')
->on('teams')
->onUpdate('cascade')
->onDelete('cascade')
;
$table->timestamps();
});
}
现在我想要掉外键season_id
public function up()
{
Schema::table('trophies', function (Blueprint $table) {
$table->dropForeign(['season_id']);
});
}
当我运行php artisan migrate时,我收到下一个错误:
In Connection.php line 664:
SQLSTATE[42000]: Syntax error or access violation: 1091 Can't DROP 'trophies_season_id_foreign'; check that column/key exists (SQL: alter table `trophies` drop foreign key `trophies_season_id_foreign`)
当我将项目从laravel 5.0升级到laravel 5.5时,可能会出现一些问题?
CREATE TABLE `trophies` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`tournament_id` int(10) unsigned DEFAULT NULL,
`season_id` int(10) unsigned DEFAULT NULL,
`user_id` int(10) unsigned DEFAULT NULL,
`team_id` int(10) unsigned DEFAULT NULL,
`created_at` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
`updated_at` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
`tourney_id` int(10) unsigned NOT NULL,
`tourney_type` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
PRIMARY KEY (`id`),
KEY `trophies_tournament_id_foreign` (`tournament_id`) USING BTREE,
KEY `trophies_season_id_foreign` (`season_id`) USING BTREE,
KEY `trophies_user_id_foreign` (`user_id`) USING BTREE,
KEY `trophies_team_id_foreign` (`team_id`) USING BTREE,
KEY `trophies_tourney_id_tourney_type_index` (`tourney_id`,`tourney_type`),
CONSTRAINT `trophies_ibfk_1` FOREIGN KEY (`season_id`) REFERENCES `seasons` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT `trophies_ibfk_2` FOREIGN KEY (`team_id`) REFERENCES `teams` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT `trophies_ibfk_3` FOREIGN KEY (`tournament_id`) REFERENCES `tournaments` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT `trophies_ibfk_4` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=130 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci
试试这个......你需要放弃关系和专栏。
$table->dropForeign(['season_id']);
$table->dropColumn('season_id');
public function up()
{
Schema::table('trophies', function (Blueprint $table) {
$table->dropForeign('trophies_ibfk_1');
});
}
这有效。但为什么CONSTRAINT'trophies_season_id_foreign'被重命名为'trophies_ibfk_1'?