I would advise to not mess with migrations on a production database. I have seen users loose months of data.
If playing with development then migrate all you want.
No matter though, backup first or chance loosing data.
Just learning Laravel here, but I see these kinds of migrations in the courses:
public function up(): void
{
Schema::create('jobs', function (Blueprint $table) {
$table->id();
$table->foreignIdFor(App\Models\Employer::class);
});
}
But I can foresee that one day, maybe 2 years from now, and many many migrations later, I might have a major refactoring where I don't end up with having an Employer class at all, but the migrations will still need to run. Or, there may be even more complicated situations where the Employer still exists but the join column is changed or renamed or the relationship goes through a pivot table rather than a belongsToOne relationship.
At that time of refactoring, it seems like it would be a huge pain to go back through the 30 old migrations and meticulously rewrite them. My instinct tells me I should just stick to manual spelling out of the migration columns like
$table->foreignKey('employer_id')->references('id')->on('employers');
Is this your sense as well, or not a big problem?
Please or to participate in this conversation.