Yep, create another migration.
But, when you're ready to ship, it's not a bad idea to try and rationalise all your migrations.
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I want to add a foreign key constraint to my user_id column in my posts table but I'm not sure how I would be able to do that, I read something about doctrine/dbal which can be used to modify columns in your database but it doesn't list anything there about adding foreign key constraints.
I want to add this code to my migration but I'm not sure if the doctrine/dbal ->change() method would work.
$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
public function up()
{
Schema::create('posts', function (Blueprint $table) {
$table->increments('id');
$table->integer('user_id');
$table->string('title');
$table->text('content');
$table->string('slug')->nullable();
$table->string('tags')->nullable();
$table->timestamps();
});
}
Am I just better off creating another migration and just adding the foreign constraint to my posts table?
Yep, create another migration.
But, when you're ready to ship, it's not a bad idea to try and rationalise all your migrations.
Please or to participate in this conversation.