【问题标题】:laravel 5.8 migration Base table or view already exist no need to drop tablelaravel 5.8迁移基表或视图已经存在无需删除表
【发布时间】:2019-08-05 08:23:35
【问题描述】:

我正在尝试在 laravel 5.8 上使用 migrate 但我收到此错误消息

C:\wamp\www\work_p\laravel\lvl1>php artisan migrate
Migrating: 2014_10_12_000000_create_users_table

   Illuminate\Database\QueryException  : SQLSTATE[42S01]: Base table or view alr
eady exists: 1050 Table 'users' already exists (SQL: create table `users` (`id`
bigint unsigned not null auto_increment primary key, `name` varchar(191) not nul
l, `email` varchar(191) not null, `email_verified_at` timestamp null, `password`
 varchar(191) not null, `remember_token` varchar(100) null, `created_at` timesta
mp null, `updated_at` timestamp null) default character set utf8mb4 collate 'utf
8mb4_unicode_ci')

  at C:\wamp\www\work_p\laravel\lvl1\vendor\laravel\framework\src\Illuminate\Dat
abase\Connection.php:664
    660|         // If an exception occurs when attempting to run a query, we'll
 format the error
    661|         // message to include the bindings with SQL, which will make th
is exception a
    662|         // lot more helpful to the developer instead of just the databa
se's errors.
    663|         catch (Exception $e) {
  > 664|             throw new QueryException(
    665|                 $query, $this->prepareBindings($bindings), $e
    666|             );
    667|         }
    668|

  Exception trace:

  1   PDOException::("SQLSTATE[42S01]: Base table or view already exists: 1050 T
able 'users' already exists")
      C:\wamp\www\work_p\laravel\lvl1\vendor\laravel\framework\src\Illuminate\Da
tabase\Connection.php:458

  2   PDOStatement::execute()
      C:\wamp\www\work_p\laravel\lvl1\vendor\laravel\framework\src\Illuminate\Da
tabase\Connection.php:458

  Please use the argument -v to see more details.

我在这里找到的所有解决方案都说我必须删除表格;

但我不能在我的表上拥有数据我在我的用户表和所有其他表上都有数据。没有删除表有没有解决这个错误的方法? 我确实尝试过使用这个解决方案

public function boot()
{
    Schema::defaultStringLength(191);
}

问题依然存在

【问题讨论】:

  • 将用户迁移文件的名称添加到migrations 表中。它将跳过再次运行相同的迁移。
  • 您在再次迁移之前是否回滚过?
  • 迁移文件的源代码会有所帮助
  • @Zeshan Khattak:你的解决方案奏效了

标签: php laravel laravel-5.8


【解决方案1】:

如果您不想专门运行该迁移,请在您的数据库上运行此查询

INSERT INTO `migrations` (`id`, `migration`, `batch`) VALUES (NULL, '2014_10_12_000000_create_users_table', '1');

【讨论】:

    猜你喜欢
    • 2019-12-30
    • 1970-01-01
    • 2022-09-30
    • 1970-01-01
    • 2021-04-08
    • 1970-01-01
    • 2020-03-03
    • 2021-03-31
    • 2019-03-05
    相关资源
    最近更新 更多