<span id="pfnzv"></span>
      <form id="pfnzv"><span id="pfnzv"></span></form><address id="pfnzv"><span id="pfnzv"><nobr id="pfnzv"></nobr></span></address>
      <form id="pfnzv"><dfn id="pfnzv"><listing id="pfnzv"></listing></dfn></form>

        <sub id="pfnzv"><address id="pfnzv"></address></sub>
          <address id="pfnzv"><form id="pfnzv"><listing id="pfnzv"></listing></form></address>
          <address id="pfnzv"><address id="pfnzv"><nobr id="pfnzv"></nobr></address></address>

            <address id="pfnzv"></address>
            0712-2888027 189-8648-0214
            微信公眾號

            孝感風信網絡科技有限公司微信公眾號

            當前位置:主頁 > 技術支持 > PHP > Laravel 5.4運行migrate命令報錯1071 Specified key was too long解決方案

            Laravel 5.4運行migrate命令報錯1071 Specified key was too long解決方案

            時間:2024-08-25來源:風信官網 點擊: 1699次
            Laravel 5.4運行migrate命令報錯1071 Specified key was too long解決方案如下:

            D:\Laravel5.4>php artisan migrate
            Migration table created successfully.


              [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

            Laravel 默認使用 utf8mb4 字符,包括支持在數據庫存儲「表情」。如果你正在運行的 MySQL release 版本低于5.7.7 或 MariaDB release 版本低于10.2.2 ,為了MySQL為它們創建索引,你可能需要手動配置遷移生成的默認字符串長度,你可以通過調用 AppServiceProvider 中的 Schema::defaultStringLength 方法來配置它:

            use Illuminate\Support\Facades\Schema;

            /**
             * 引導任何應用程序服務。
             *
             * @return void
             */
            public function boot()
            {
                Schema::defaultStringLength(191);
            }

            或者你可以為數據庫開啟 innodb_large_prefix 選項,有關如何正確開啟此選項的說明請查閱數據庫文檔。

            修改文件:\app\Providers\AppServiceProvider.php

            修改之后的源代碼:

             <?php
            
            namespace App\Providers;
            
            use Illuminate\Support\ServiceProvider;
            use Illuminate\Support\Facades\Schema;
            
            class AppServiceProvider extends ServiceProvider
            {
                /**
                 * Bootstrap any application services.
                 *
                 * @return void
                 */
                public function boot()
                {
                    Schema::defaultStringLength(191);
                }
            
                /**
                 * Register any application services.
                 *
                 * @return void
                 */
                public function register()
                {
                    //
                }
            }
            

            重新運行php artisan migrate命令創建數據庫

            D:\phpStudy\Laravel5.4>php artisan migrate
            Migration table created successfully.
            Migrating: 2014_10_12_000000_create_users_table
            Migrated:  2014_10_12_000000_create_users_table
            Migrating: 2014_10_12_100000_create_password_resets_table
            Migrated:  2014_10_12_100000_create_password_resets_table
            欄目列表
            推薦內容
            熱點內容
            展開
            国产精久久久久无码AV动漫|最新亚洲精品国偷自产在线|2021亚洲色中文字幕在线|最新无码av中文字专区 情欲美妇紧致敏感 国产免费AⅤ片在线播放 人妻爽爽免费在线视频 51精品国产人成在线观看 色偷偷av一区二区三区
            <span id="pfnzv"></span>
                <form id="pfnzv"><span id="pfnzv"></span></form><address id="pfnzv"><span id="pfnzv"><nobr id="pfnzv"></nobr></span></address>
                <form id="pfnzv"><dfn id="pfnzv"><listing id="pfnzv"></listing></dfn></form>

                  <sub id="pfnzv"><address id="pfnzv"></address></sub>
                    <address id="pfnzv"><form id="pfnzv"><listing id="pfnzv"></listing></form></address>
                    <address id="pfnzv"><address id="pfnzv"><nobr id="pfnzv"></nobr></address></address>

                      <address id="pfnzv"></address>