Laravel won#39;t let me migrate a table because it already exists(Laravel 不允许我迁移表,因为它已经存在)
问题描述
我正在尝试使用 Laravel Migration 创建 SQL 表,但它不让我使用.
I am trying to use Laravel Migration to create SQL tables but it won't let me.
这里是错误:
SQLSTATE[42S01]:基表或视图已经存在:1050 表'mytable' 已经存在
SQLSTATE[42S01]: Base table or view already exists: 1050 Table 'mytable' already exists
这是我的代码:
Schema::create('mytable', function (Blueprint $table) {
$table->increments('id');
$table->foreign('othertable_id')
->references('id')->on('othertable')
->onDelete('cascade');
$table->string('variable');
$table->timestamps();
});
}
{
Schema::drop('mytable');
}
我还检查了其他迁移是否称为mytable",但它们不是,所以我不确定这是从哪里来的.
I have also checked if other migrations are called "mytable" but they are not, so I am not sure where this come from.
我尝试了以下方法:
第一次
php artisan migrate:refresh
这给了我一个错误
然后我删除了整个数据库并使用:
And then I deleted the entire database altogheter and used:
php artisan migrate
还是报错
推荐答案
do composer dump,手动从数据库中删除表,并删除要从中删除的表的迁移条目迁移表并再次重新运行迁移以查看会发生什么.
do composer dump, remove the table manually from the database and also remove the migration entry for the the table you want to remove from the migration table and rerun the migration again to see what happens.
这篇关于Laravel 不允许我迁移表,因为它已经存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Laravel 不允许我迁移表,因为它已经存在
基础教程推荐
- PHP 类:全局变量作为类中的属性 2021-01-01
- 如何替换eregi() 2022-01-01
- 如何在 Laravel 5.3 注册中添加动态下拉列表列? 2021-01-01
- 学说 dbal querybuilder 作为准备好的语句 2022-01-01
- 有什么方法可以用编码 UTF-8 而不是 Unicode 返回 PHP`json_encode`? 2021-01-01
- Cron Jobs 调用带有变量的 PHP 脚本 2022-01-01
- 在PHP中根据W3C规范Unicode 2022-01-01
- YouTube API v3 点赞视频,但计数器不增加 2022-01-01
- 如何在 Laravel 中使用 React Router? 2022-01-01
- PHP PDO MySQL 查询 LIKE ->多个关键词 2021-01-01
