每当我尝试将数据库迁移到Laravel时,我都会遇到此问题。
我尝试了几种选择,但似乎都不起作用。 预先感谢!
用户表:
Schema::create('users', function (Blueprint $table) {
$table->bigIncrements('id');
$table->string('name');
$table->string('avatar',100)->nullable();
$table->string('country',100)->nullable();
$table->string('email')->unique();
$table->timestamp('email_verified_at')->nullable();
$table->string('password');
$table->unsignedBigInteger('product_id')->unsigned();
$table->foreign('product_id')->references('id')->on('products');
$table->rememberToken();
$table->timestamps();
});
}
创建产品表:
enter code here:
Schema::create('products', function (Blueprint $table) {
$table->bigIncrements('id');
$table->string('name', 100);
$table->decimal('price', 8, 2);
$table->string('image', 100);
$table->unsignedBigInteger('user_id')->unsigned();
$table->foreign('user_id')->references('id')->on('users');
$table->timestamps();
});
}
将类别ID添加到圆柱产品:
enter code here:
Schema::table('products', function (Blueprint $table) {
$table->unsignedBigInteger('category_id')->nullable();
$table->foreign('category_id')->references('id')->on('categories');
});
}
兴趣表:
enter code here:
Schema::create('interests', function (Blueprint $table) {
$table->bigIncrements('id');
$table->string('name',100)->nullable();
$table->timestamps();
});
}
品牌表:
enter code here:
Schema::create('brands', function (Blueprint $table) {
$table->bigIncrements('id');
$table->string('name')->nullable();
$table->timestamps();
});
}
在产品表中添加品牌ID:
enter code here:
Schema::table('products', function (Blueprint $table) {
$table->unsignedBigInteger('brand_id')->nullable();
$table->foreign('brand_id')->references('id')->on('brands');
});
}
创建类别兴趣:
enter code here:
Schema::table('products', function (Blueprint $table) {
$table->unsignedBigInteger('brand_id')->nullable();
$table->foreign('brand_id')->references('id')->on('brands');
});
}
2 在此处输入代码:
PDOStatement :: execute() /Users/Ezequiel/Desktop/dandelion/vendor/laravel/framework/src/Illuminate/Database/Connection.php:458