sanduniYW
sanduniYW

Reputation: 733

how to edit original table in laravel migration?

My question is how to edit original table in laravel migration?

That is, suppose to there are two table have as Teacher and Children. As well as Student table has foreign key as TeacherId. (Teacher_id refer to TeacherId in Teacher table) Some error reason I want to drop Teacher table or edit Teacher table. Then general error occur without original key table cannot had foreign key.

So how can I drop the Teacher table or edit Teacher table without drop Student table? Have some way to do that?

Upvotes: 0

Views: 53

Answers (2)

Bart
Bart

Reputation: 1957

You should code your laravel migrations in a way, so you can revert it all back, under down() method.

Sometimes you get stuck, in a way that, migrate or migrate:rollback command produces an error.

Then you should modify your db structure, by hand (using mysql command, workbench, or any other sql tools), to bring your migrations to working again...

And finally targetting your question...

You cannot create table and add foreign constraints in one commit to db, so in order, to do that, you need to add new declaration in your migration up() like Table:... after Schema:create... and add your foreign keys here. Remember to do the opposite in down() method...

Upvotes: 0

user1669496
user1669496

Reputation: 33058

First you need to drop the foreign key on the your Student table (or maybe the teacher_id column entirely if you no longer have a Teacher table), then you should be able to drop the Teacher table assuming no more foreign keys are referencing the Student table.

Upvotes: 1

Related Questions