<legend id='bpKJ7'><style id='bpKJ7'><dir id='bpKJ7'><q id='bpKJ7'></q></dir></style></legend>
    • <bdo id='bpKJ7'></bdo><ul id='bpKJ7'></ul>
    <i id='bpKJ7'><tr id='bpKJ7'><dt id='bpKJ7'><q id='bpKJ7'><span id='bpKJ7'><b id='bpKJ7'><form id='bpKJ7'><ins id='bpKJ7'></ins><ul id='bpKJ7'></ul><sub id='bpKJ7'></sub></form><legend id='bpKJ7'></legend><bdo id='bpKJ7'><pre id='bpKJ7'><center id='bpKJ7'></center></pre></bdo></b><th id='bpKJ7'></th></span></q></dt></tr></i><div id='bpKJ7'><tfoot id='bpKJ7'></tfoot><dl id='bpKJ7'><fieldset id='bpKJ7'></fieldset></dl></div>

    1. <tfoot id='bpKJ7'></tfoot>
    2. <small id='bpKJ7'></small><noframes id='bpKJ7'>

      删除带有外键 Laravel 错误的列:一般错误:1025 重命名错误

      Dropping column with foreign key Laravel error: General error: 1025 Error on rename(删除带有外键 Laravel 错误的列:一般错误:1025 重命名错误)
      <i id='B6oIu'><tr id='B6oIu'><dt id='B6oIu'><q id='B6oIu'><span id='B6oIu'><b id='B6oIu'><form id='B6oIu'><ins id='B6oIu'></ins><ul id='B6oIu'></ul><sub id='B6oIu'></sub></form><legend id='B6oIu'></legend><bdo id='B6oIu'><pre id='B6oIu'><center id='B6oIu'></center></pre></bdo></b><th id='B6oIu'></th></span></q></dt></tr></i><div id='B6oIu'><tfoot id='B6oIu'></tfoot><dl id='B6oIu'><fieldset id='B6oIu'></fieldset></dl></div>

            <tbody id='B6oIu'></tbody>
          • <small id='B6oIu'></small><noframes id='B6oIu'>

            • <bdo id='B6oIu'></bdo><ul id='B6oIu'></ul>
              <legend id='B6oIu'><style id='B6oIu'><dir id='B6oIu'><q id='B6oIu'></q></dir></style></legend>

              1. <tfoot id='B6oIu'></tfoot>

                本文介绍了删除带有外键 Laravel 错误的列:一般错误:1025 重命名错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                I've created a table using migration like this:

                public function up()
                {
                    Schema::create('despatch_discrepancies',  function($table) {
                        $table->increments('id')->unsigned();
                        $table->integer('pick_id')->unsigned();
                        $table->foreign('pick_id')->references('id')->on('picks');
                        $table->integer('pick_detail_id')->unsigned();
                        $table->foreign('pick_detail_id')->references('id')->on('pick_details');
                        $table->integer('original_qty')->unsigned();
                        $table->integer('shipped_qty')->unsigned();
                    });
                }
                
                public function down()
                {
                    Schema::drop('despatch_discrepancies');
                }
                

                I need to change this table and drop the foreign key reference & column pick_detail_id and add a new varchar column called sku after pick_id column.

                So, I've created another migration, which looks like this:

                public function up()
                {
                    Schema::table('despatch_discrepancies', function($table)
                    {
                        $table->dropForeign('pick_detail_id');
                        $table->dropColumn('pick_detail_id');
                        $table->string('sku', 20)->after('pick_id');
                    });
                }
                
                public function down()
                {
                    Schema::table('despatch_discrepancies', function($table)
                    {
                        $table->integer('pick_detail_id')->unsigned();
                        $table->foreign('pick_detail_id')->references('id')->on('pick_details');
                        $table->dropColumn('sku');
                    });
                }
                

                When I run this migration, I get the following error:

                [IlluminateDatabaseQueryException]
                SQLSTATE[HY000]: General error: 1025 Error on rename of './dev_iwms_reboot/despatch_discrepancies' to './dev_iwms_reboot/#sql2-67c-17c464' (errno: 152) (SQL: alter table despatch_discrepancies drop foreign key pick_detail_id)

                [PDOException]
                SQLSTATE[HY000]: General error: 1025 Error on rename of './dev_iwms_reboot/despatch_discrepancies' to './dev_iwms_reboot/#sql2-67c-17c464' (errno: 152)

                When I try to reverse this migration by running php artisan migrate:rollback command, I get a Rolled back message, but it's not actually doing anything in the database.

                Any idea what might be wrong? How do you drop a column that has a foreign key reference?

                解决方案

                It turns out; when you create a foreign key like this:

                $table->integer('pick_detail_id')->unsigned();
                $table->foreign('pick_detail_id')->references('id')->on('pick_details');
                

                Laravel uniquely names the foreign key reference like this:

                <table_name>_<foreign_table_name>_<column_name>_foreign
                despatch_discrepancies_pick_detail_id_foreign (in my case)
                

                Therefore, when you want to drop a column with foreign key reference, you have to do it like this:

                $table->dropForeign('despatch_discrepancies_pick_detail_id_foreign');
                $table->dropColumn('pick_detail_id');
                

                Update:

                Laravel 4.2+ introduces a new naming convention:

                <table_name>_<column_name>_foreign
                

                这篇关于删除带有外键 Laravel 错误的列:一般错误:1025 重命名错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                Laravel 4 - Connect to other database(Laravel 4 - 连接到其他数据库)
                Call external API function from controller, LARAVEL 4(从控制器调用外部 API 函数,LARAVEL 4)
                Empty string instead of null values Eloquent(空字符串而不是空值 Eloquent)
                quot;laravel.logquot; could not be opened: failed to open stream(“laravel.log无法打开:无法打开流)
                Displaying the Error Messages in Laravel after being Redirected from controller(从控制器重定向后在 Laravel 中显示错误消息)
                Laravel Creating Dynamic Routes to controllers from Mysql database(Laravel 从 Mysql 数据库创建到控制器的动态路由)

                  <tbody id='ELErG'></tbody>
                  • <bdo id='ELErG'></bdo><ul id='ELErG'></ul>
                  • <legend id='ELErG'><style id='ELErG'><dir id='ELErG'><q id='ELErG'></q></dir></style></legend>
                        <tfoot id='ELErG'></tfoot>
                        <i id='ELErG'><tr id='ELErG'><dt id='ELErG'><q id='ELErG'><span id='ELErG'><b id='ELErG'><form id='ELErG'><ins id='ELErG'></ins><ul id='ELErG'></ul><sub id='ELErG'></sub></form><legend id='ELErG'></legend><bdo id='ELErG'><pre id='ELErG'><center id='ELErG'></center></pre></bdo></b><th id='ELErG'></th></span></q></dt></tr></i><div id='ELErG'><tfoot id='ELErG'></tfoot><dl id='ELErG'><fieldset id='ELErG'></fieldset></dl></div>

                          <small id='ELErG'></small><noframes id='ELErG'>