laravel5.5 遷移資料庫 出錯(三)
阿新 • • 發佈:2019-01-23
錯誤提示
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個表,實際建立了兩個。忽略了錯誤。
下面再對資料庫進行操作時,就會提示這種錯誤。
解決辦法:
- 將資料庫中的表全部刪除
- 在
AppServiceProvider.php
中新增
use Illuminate\Support\Facades\Schema;
public function boot()
{
Schema::defaultStringLength(191);
}
- 重新執行
php artisan migrate