Igo*_*iuk 0 foreign-keys laravel
我的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();
});
}
Run Code Online (Sandbox Code Playgroud)
现在我想删除外键 season_id
public function up()
{
Schema::table('trophies', function (Blueprint $table) {
$table->dropForeign(['season_id']);
});
}
Run Code Online (Sandbox Code Playgroud)
当我运行 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`)
Run Code Online (Sandbox Code Playgroud)
也许当我将我的项目从 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
Run Code Online (Sandbox Code Playgroud)
小智 5
试试这个...你需要删除关系和列。
$table->dropForeign(['season_id']);
$table->dropColumn('season_id');
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2842 次 |
| 最近记录: |