PHP artisan migration不会迁移所有表 [英] PHP artisan migrate does not migrate all tables
问题描述
我正在尝试将表迁移到数据库.我正在上Laravel课程,但出现错误.
I am trying to migrate tables to the database. I am doing a course on Laravel and i got an error.
C:\laragon\www\blog
λ php artisan migrate
Migration table created successfully.
Migrating: 2014_10_12_000000_create_users_table
Illuminate\Database\QueryException : SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 76
7 bytes (SQL: alter table `users` add unique `users_email_unique`(`email`))
at C:\laragon\www\blog\vendor\laravel\framework\src\Illuminate\Database\Connection.php:665
661| // If an exception occurs when attempting to run a query, we'll format the error
662| // message to include the bindings with SQL, which will make this exception a
663| // lot more helpful to the developer instead of just the database's errors.
664| catch (Exception $e) {
> 665| throw new QueryException(
666| $query, $this->prepareBindings($bindings), $e
667| );
668| }
669|
Exception trace:
1 PDOException::("SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 767 bytes")
C:\laragon\www\blog\vendor\laravel\framework\src\Illuminate\Database\Connection.php:459
2 PDOStatement::execute()
C:\laragon\www\blog\vendor\laravel\framework\src\Illuminate\Database\Connection.php:459
Please use the argument -v to see more details.
C:\laragon\www\blog
λ
我已经在PHPMyAdmin中创建了一个数据库,当我执行迁移时,它会从4个表中迁移2个,这意味着它们在.env文件上已正确连接.我试图通过PHPMyAdmin手动添加那些表,但是在此之后,当我制作工厂文件和播种器时,我遇到了不同的错误,因此我陷入了困境.
I have created a database in PHPMyAdmin and when I perform migration it migrates 2 from 4 tables which means that they are connected properly on .env file. I tried to add those tables manually through PHPMyAdmin but after that when I make factory file and seeder I different error so I am stuck on this.
在我跑步之前:
λ php artisan make:migration create_todos_table
Created Migration: 2019_11_27_081314_create_todos_table
一切正常,但是在迁移时出现错误.谢谢
and all went ok but when migrating i got an error. Thanks
推荐答案
,位于您的App \ Providers \ AppServiceProvider.php
use Illuminate\Support\Facades\Schema;
public function boot()
{
Schema::defaultStringLength(191);
}
然后运行
php artisan migrate
请参阅
[ https://laravel-news.com /laravel-5-4-key-too-long-error]
这篇关于PHP artisan migration不会迁移所有表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!