**
laravel中ERP管理系统数据库迁移出现提示字段过长的解决方案
**
1.问题描述
在进行ERP系统数据库迁移时,使用php artisan key:migrate时显示如下问题:
代码显示:
mmd@DESKTOP-LMDMI8L MINGW64 /e/phpstudy_pro/WWW/pc
$ 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 lon
g; max key length is 1000 bytes (SQL: alter table `users` add unique `users_email_u
nique`(`email`))
at E:\phpstudy_pro\WWW\pc\vendor\laravel\framework\src\Illuminate\Database\Connec
tion.php:671
667| // If an exception occurs when attempting to run a query, we'll fo
rmat the error
668| // message to include the bindings with SQL, which will make this
exception a
669| // lot more helpful to the developer instead of just the database'
s errors.
670| catch (Exception $e) {
> 671| throw new QueryException(
672| $query, $this->prepareBindings($bindings), $e
673| );
674| }
675|
1 E:\phpstudy_pro\WWW\pc\vendor\doctrine\dbal\lib\Doctrine\DBAL\Driver\PDO\Exce
ption.php:18
Doctrine\DBAL\Driver\PDO\Exception::("SQLSTATE[42000]: Syntax error or access
violation: 1071 Specified key was too long; max key length is 1000 bytes")
2 E:\phpstudy_pro\WWW\pc\vendor\doctrine\dbal\lib\Doctrine\DBAL\Driver\PDOState
ment.php:119
Doctrine\DBAL\Driver\PDO\Exception::new(Object(PDOException))
主要是数据库版本过低,字段定义是不匹配,不兼容。
问题的解决方案:
1.由于laravel本身架构的问题需要在原有的文件上增加两行配置,如下图:
继续执行 php artisan key:migrate:
查看还是数据库不匹配的问题
经过排除,发现是phpstudy的版本有问题更新至最新再排查(安装完毕后记得重启,会更新数据):
记得修改php的环境变量的路径:
将代码移植www文件下,配置虚拟域名,修改伪静态。
伪静态代码如下:
<IfModule mod_rewrite.c>
Options +FollowSymlinks -Multiviews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php? [L,E=PATH_INFO:$1]
</IfModule>
安装步骤执行一遍即可完成数据库迁移(排查完成):