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

    1. <small id='1PhWC'></small><noframes id='1PhWC'>

    2. <tfoot id='1PhWC'></tfoot>

          <bdo id='1PhWC'></bdo><ul id='1PhWC'></ul>

        SQLSTATE [HY000]:一般错误:1005 无法创建表 - Laravel 4

        SQLSTATE[HY000]: General error: 1005 Can#39;t create table - Laravel 4(SQLSTATE [HY000]:一般错误:1005 无法创建表 - Laravel 4)

        1. <small id='0xYqe'></small><noframes id='0xYqe'>

              <tfoot id='0xYqe'></tfoot><legend id='0xYqe'><style id='0xYqe'><dir id='0xYqe'><q id='0xYqe'></q></dir></style></legend>
                  <tbody id='0xYqe'></tbody>
                <i id='0xYqe'><tr id='0xYqe'><dt id='0xYqe'><q id='0xYqe'><span id='0xYqe'><b id='0xYqe'><form id='0xYqe'><ins id='0xYqe'></ins><ul id='0xYqe'></ul><sub id='0xYqe'></sub></form><legend id='0xYqe'></legend><bdo id='0xYqe'><pre id='0xYqe'><center id='0xYqe'></center></pre></bdo></b><th id='0xYqe'></th></span></q></dt></tr></i><div id='0xYqe'><tfoot id='0xYqe'></tfoot><dl id='0xYqe'><fieldset id='0xYqe'></fieldset></dl></div>
                  <bdo id='0xYqe'></bdo><ul id='0xYqe'></ul>
                • 本文介绍了SQLSTATE [HY000]:一般错误:1005 无法创建表 - Laravel 4的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我在执行 php artisan 迁移时收到此错误.我的迁移文件有问题吗?还是我的模型编码错误?但是即使模型中有问题,迁移也应该可以工作?

                  I get this error when I do php artisan migrate. Is there something wrong in my migration files? Or is it possible my models are wrong coded? But the migrations should work even there is something wrong in the models?

                  [Exception]                                                                  
                    SQLSTATE[HY000]: General error: 1005 Can't create table 'festival_aid.#sql-  
                    16643_2033' (errno: 150) (SQL: alter table `gigs` add constraint gigs_band_  
                    id_foreign foreign key (`band_id`) references `bands` (`band_id`) on delete  
                     cascade) (Bindings: array (                                                 
                    ))
                  
                  [PDOException]                                                               
                    SQLSTATE[HY000]: General error: 1005 Can't create table 'festival_aid.#sql-  
                    16643_2033' (errno: 150)
                  

                  演出迁移

                  public function up()
                      {
                          Schema::create('gigs', function($table)
                          {
                              $table->increments('gig_id');
                  
                              $table->dateTime('gig_startdate');
                  
                              $table->integer('band_id')->unsigned();
                              $table->integer('stage_id')->unsigned();
                  
                              $table->foreign('band_id')
                                  ->references('band_id')->on('bands')
                                  ->onDelete('cascade');
                  
                              $table->foreign('stage_id')
                                  ->references('stage_id')->on('stages')
                                  ->onDelete('cascade');
                          });
                  
                      public function down()
                      {
                          Schema::table('gigs', function($table)
                          {
                              Schema::drop('gigs');
                              $table->dropForeign('gigs_band_id_foreign');
                              $table->dropForeign('gigs_stage_id_foreign');
                          });
                      }
                  

                  乐队迁移

                  public function up()
                      {
                          Schema::create('bands', function($table)
                          {
                              $table->increments('band_id');
                  
                              $table->string('band_name');
                              $table->text('band_members');
                              $table->string('band_genre');
                              $table->dateTime('band_startdate');
                          });
                      }
                  
                      public function down()
                      {
                          Schema::table('bands', function(Blueprint $table)
                          {
                              Schema::drop('bands');
                          });
                      }
                  

                  模型乐队

                  <?php
                  
                  class Band extends Eloquent {
                  
                      protected $primaryKey = 'band_id';
                  
                      public function gig()
                      {
                          return $this->hasOne('Gig', 'band_id', 'band_id');
                      }
                  }
                  

                  模型演出

                  <?php
                  
                  class Gig extends Eloquent {
                      protected $primaryKey = 'gig_id';
                  
                      public function gig()
                      {
                          return $this->belongsTo('Band', 'band_id', 'band_id');
                      }
                  
                      public function stage()
                      {
                          return $this->belongsTo('Stage', 'stage_id', 'stage_id');
                      }
                  }
                  

                  推荐答案

                  必须先创建表,再创建外键:

                  You must first create the table, then create the foreign keys:

                  Schema::create('gigs', function($table)
                  {
                      $table->increments('gig_id');
                  
                      $table->dateTime('gig_startdate');
                  
                      $table->integer('band_id')->unsigned();
                      $table->integer('stage_id')->unsigned();
                  });
                  
                  Schema::table('gigs', function($table)
                  {
                      $table->foreign('band_id')
                          ->references('band_id')->on('bands')
                          ->onDelete('cascade');
                  
                      $table->foreign('stage_id')
                          ->references('stage_id')->on('stages')
                          ->onDelete('cascade');
                  });
                  

                  并且您的 bands 表应该首先迁移,因为 gigs 正在引用它.

                  And your bands table should migrate first, since the gigs is referencing it.

                  这篇关于SQLSTATE [HY000]:一般错误:1005 无法创建表 - Laravel 4的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  DeepL的翻译效果还是很强大的,如果我们要用php实现DeepL翻译调用,该怎么办呢?以下是代码示例,希望能够帮到需要的朋友。 在这里需要注意,这个DeepL的账户和api申请比较难,不支持中国大陆申请,需要拥有香港或者海外信用卡才行,没账号的话,目前某宝可以
                  PHP通过phpspreadsheet导入Excel日期,导入系统后,全部变为了4开头的几位数字,这是为什么呢?原因很简单,将Excel的时间设置问文本,我们就能看到该日期本来的数值,上图对应的数值为: 要怎么解决呢?进行数据转换就行,这里可以封装方法,或者用第三方的
                  mediatemple - can#39;t send email using codeigniter(mediatemple - 无法使用 codeigniter 发送电子邮件)
                  Laravel Gmail Configuration Error(Laravel Gmail 配置错误)
                  Problem with using PHPMailer for SMTP(将 PHPMailer 用于 SMTP 的问题)
                  Issue on how to setup SMTP using PHPMailer in GoDaddy server(关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题)
                    <bdo id='5udf0'></bdo><ul id='5udf0'></ul>
                        <tbody id='5udf0'></tbody>
                          1. <small id='5udf0'></small><noframes id='5udf0'>

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

                            <legend id='5udf0'><style id='5udf0'><dir id='5udf0'><q id='5udf0'></q></dir></style></legend>