Laravel- 数据库迁移
為什么80%的碼農(nóng)都做不了架構(gòu)師?>>> ??
?
問題1:?默認(rèn)字符串字段的長度是255
D:\Dev_PHP\wamp\www\laravels\BaseManage>php artisan migrate
? [Illuminate\Database\QueryException]
? SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 1000 bytes (SQL: alter table `users` add unique `users_email_unique`(`email`))
? [PDOException]
? SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 1000 bytes
參考:http://www.cnblogs.com/betx/p/6544090.html
思考:
(1) 生產(chǎn)環(huán)境如果使用了artisan的數(shù)據(jù)庫rollback或者reset命令,則后果很嚴(yán)重,因此可以在down方法里面做個判斷,生產(chǎn)環(huán)境則不執(zhí)行drop table的操作。
(2) 遷移文件: Create table的時候,如果對表有修改,可以增加table_update遷移文件,在里面的up方法增加、刪除、修改字段。
?? ?Schema::table("users",function (Blueprint $table){
?? ??? ??? ?$table->string("name2");
?? ??? ?});
(3) 本地Hoozt_ScreenManage在連接238.61數(shù)據(jù)庫的時候,laravel的log報(bào)錯說連接不上數(shù)據(jù)庫,貌似首先在嘗試使用默認(rèn)的配置而不是自己寫的配置,待查。
?? ?Next exception 'Illuminate\Database\QueryException' with message 'SQLSTATE[HY000] [1045] Access denied for user 'forge'@'localhost' (using password: NO) (SQL: select * from `admin_permissions`)' in D:\Dev_PHP\wamp\www\laravels\baier_gxy\Hoozt_ScreenManage\vendor\laravel\framework\src\Illuminate\Database\Connection.php:647
(4) Hoozt_ScreenManage的AreaInitSeeder里面的SQL字符串,使用了Heredoc方式聲明字符串;
?? ?http://php.net/manual/zh/language.types.string.php#language.types.string.syntax.heredoc
(5) HereDoc方式 定義字符串和數(shù)組, 然后當(dāng)成sql的key-value如何?
(6) 如果刪除一個Migration文件,但是又不方便使用migration reset或者 rollback,可以這么做:
? ?(1)刪除遷移文件; (2)執(zhí)行composer dump-autoload;?(3) 手工在數(shù)據(jù)庫改動相應(yīng)的地方;
????http://www.jianshu.com/p/7332dbb69898
? ? https://laravel-china.org/topics/1002/deep-composer-autoload
? ? http://www.jyguagua.com/?p=2602
? ??
?? ?
問題2:
多數(shù)據(jù)庫連接問題
http://blog.csdn.net/u011132987/article/details/54669254
http://wenda.golaravel.com/question/57
?
轉(zhuǎn)載于:https://my.oschina.net/jrrx/blog/891396
總結(jié)
以上是生活随笔為你收集整理的Laravel- 数据库迁移的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: JavaScript中常用的BOM属性
- 下一篇: 卵泡多少正常(正常卵巢有几个卵泡)