Php 如何使外键与int类型相同?
我在laravel中声明了以下迁移文件:Php 如何使外键与int类型相同?,php,laravel-4,database-migration,Php,Laravel 4,Database Migration,我在laravel中声明了以下迁移文件: <?php use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Migrations\Migration; class CreateProductsTable extends Migration { /** * Run the migrations. * * @return void */ public fu
<?php
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateProductsTable extends Migration {
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('products' , function($table){
$table->increments('id');
$table->integer('category_id');
$table->string('title');
$table->text('description');
$table->decimal('height' , 6 , 2);
$table->decimal('width' , 6 , 2);
$table->decimal('length' , 6 , 2);
$table->string('color');
$table->string('material');
$table->timestamps();
});
Schema::table('products' , function($table){
$table->foreign('category_id')->references('id')->on('categories');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::drop('products');
}
}
int(11)
如何使两者都为int(10) 我猜您以前的迁移是在以前版本的Laravel上运行的。如果是这种情况,您可以直接在数据库中将categories.id
的列类型修改为int(11)
否则,您可以使用INT(10)
来添加列
要确认版本更改导致此问题的假设,您可以在空数据库中运行所有迁移,并查看是否存在相同问题。我猜您以前的迁移是在以前版本的Laravel上运行的。如果是这种情况,您可以直接在数据库中将
categories.id
的列类型修改为int(11)
Schema::table('products', function($table)
{
$table->integer('id, 10');
});
否则,您可以使用INT(10)
来添加列
要确认版本更改导致此问题的假设,可以在空数据库中运行所有迁移,并查看是否存在相同的问题
Schema::table('products', function($table)
{
$table->integer('id, 10');
});