When creating migrations, can I add "unsigned" and "index" in this way?
$table->integer('user_id')->unsiqned()->index();
or only "unsigned", like this:
$table->integer('recipe_id')->unsiqned();
When I do this on my table "user_recipes", only the primary key becomes unsigned. User_id doesn't get "unsigned" nor "index":
public function up()
{
Schema::create('user_recipes', function (Blueprint $table) {
$table->increments('recipe_id')->unsiqned();
$table->integer('user_id')->unsiqned()->index();
$table->text('recipe_content');
$table->timestamps();
$table->boolean('hasbeenconverted', 50);
$table->foreign('user_id')->references('id')->on('users');
});
}
But the above column "recipe_content" becomes "unique" and indexed - how come??
I do the same thing in the table "user_custom_categories", and in this case the user_id became unsigned but no index was added. The auto increment primary key went unsigned also.
public function up()
{
Schema::create('user_custom_categories', function (Blueprint $table) {
$table->increments('cat_id')->unsiqned();
$table->integer('user_id')->unsigned()->index();
$table->string('custom_category', 50);
$table->foreign('user_id')->references('id')->on('users');
});
}
And on a third table "recipe_category_relations", only the primary "id"-column became unsigned with this code:
public function up()
{
Schema::create('recipe_category_relations', function (Blueprint $table) {
$table->increments('id')->unsiqned();
$table->integer('recipe_id')->unsiqned();
$table->integer('category_id')->unsiqned();
$table->timestamps();
// $table->foreign('recipe_id')->references('recipe_id')->on('user_recipes');
// $table->foreign('category_id')->references('cat_id')->on('user_custom_categories');
});
}
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire