SQLSTATE [HY000]:常规错误:1005无法创建表

时间:2014-01-07 23:11:05

标签: php laravel-4

当我运行php artisan migrate时,我不断收到此错误:

[Illuminate\Database\QueryException]
  SQLSTATE[HY000]: General error: 1005 Can't create table 'laracart.#sql-25b_
  3' (errno: 150) (SQL: alter table `customers_orders` add constraint custome
  rs_orders_products_id_foreign foreign key (`products_id`) references `produ
  cts` (`id`) on delete cascade on update cascade)

这是客户订单的架构:

Schema::create('customers_orders', function(Blueprint $table)
        {
            $table->engine = 'InnoDB';

            $table->increments('id');
            $table->integer('customers_id')->unsigned();
            $table->integer('products_id')->unsigned();

            $table->foreign('customers_id')
                  ->references('id')
                  ->on('customers')
                  ->onDelete('cascade')
                  ->onUpdate('cascade');

            $table->foreign('products_id')
                  ->references('id')
                  ->on('products')
                  ->onDelete('cascade')
                  ->onUpdate('cascade');

            $table->integer('quantity')->unsigned();
            $table->float('unit_price');
            $table->float('subtotal');
            $table->string('shipping_price');
            $table->float('grand_total');
            $table->string('status');
            $table->string('tracking_number');
            $table->string('payment_reference');

            $table->timestamps();
            $table->integer('is_deleted')->default('0');
            $table->softDeletes();
        });

和产品架构

Schema :: create('products',function(Blueprint $ table)         {             $ table-> engine ='InnoDB';

        $table->increments('id');
        $table->integer('categories_id')->unsigned();
        $table->foreign('categories_id')
              ->references('id')
              ->on('categories')
              ->onDelete('cascade')
              ->onUpdate('cascade');

        $table->string('name')->unique();
        $table->text('description');
        $table->string('sku')->nullable();
        $table->float('price')->default('0.00');
        $table->float('weight')->default('0');
        $table->text('meta_title')->nullable();
        $table->text('meta_description')->nullable();
        $table->integer('is_visible')->default('1');

        $table->timestamps();
        $table->integer('is_deleted')->default('0');
        $table->softDeletes();
    });

0 个答案:

没有答案