【问题标题】:Add more column in existing table but it doesn't [duplicate]在现有表中添加更多列,但它没有 [重复]
【发布时间】:2018-10-30 04:10:52
【问题描述】:
$ php artisan migrate

In Connection.php line 647:

  SQLSTATE[42S01]: Base table or view already exists: 1050 Table 'users' alre
  ady exists (SQL: create table `users` (`id` int unsigned not null auto_incr
  ement primary key, `name` varchar(191) not null, `email` varchar(191) not n
  ull, `password` varchar(191) not null, `remember_token` varchar(100) null,
  `created_at` timestamp null, `updated_at` timestamp null) default character
   set utf8mb4 collate utf8mb4_unicode_ci)


In Connection.php line 449:

  SQLSTATE[42S01]: Base table or view already exists: 1050 Table 'users' alre
  ady exists

我正在尝试在 users 表中添加更多列,但我不能。在终端我写命令 php artisan migrate 但基表或视图已经存在:1050 表'用户'已经存在。我现在能做什么?

【问题讨论】:

  • 不要使用Schema::create 使用Schema::table 添加更多列

标签: php mysql laravel artisan-migrate


【解决方案1】:

使用 PHP artisan migrate:refresh 它将删除所有表并再次创建所有 或使用 Schema::table 添加更多列

【讨论】:

  • 我也尝试过,但 SQLSTATE[42S01]: 基表或视图已存在:1050 表“用户”已存在。
  • 去数据库手动删除所有表
  • 谢谢。它正在工作。
  • 那么请投票
【解决方案2】:

你需要引用表而不是调用create方法

Schema::table('users', function (Blueprint $table) {
    $table->string('email');
});

Laravel Documentation

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多