laravel5.5 迁移数据库 出错(三)

错误提示

In Connection.php line 664:

  SQLSTATE[42S01]: Base table or view already exists: 1050 Table 'users' already exists (SQL: create table `users`
  (`id` int unsigned not null auto_increment primary key, `name` varchar(191) not null, `email` varchar(191) not nu
  ll, `password` varchar(191) not null, `remember_token` varchar(100) null, `created_at` timestamp null, `updated_a
  t` timestamp null) default character set utf8mb4 collate utf8mb4_unicode_ci)


In Connection.php line 458:

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

实际的错误原因却不是在这里,而是我在上一步的时候就已经错了。
上一步错误提示:

Migration table created successfully.

In Connection.php line 664:

  SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 767 bytes (
  SQL: alter table `users` add unique `users_email_unique`(`email`))


In Connection.php line 458:

  SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 767 bytes

上一步创建表时少创建了一个表,本来需要创建3个表,实际创建了两个。忽略了错误。
下面再对数据库进行操作时,就会提示这种错误。

解决办法:

  1. 将数据库中的表全部删除
  2. AppServiceProvider.php中添加
use Illuminate\Support\Facades\Schema;

public function boot()
{
    Schema::defaultStringLength(191);
}
  1. 重新执行php artisan migrate

https://www.cnblogs.com/luxia/p/7929651.html

你可能感兴趣的:(laravel-错误)