Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DbMigration move column with data

I have two tables: A and B. Both tables are filled with data.

Table A contain column: col. I want to move col with data from table A to table B. After all I want to drop col from table A. Should I write raw sql to copy data or there are method to copy data.

like image 337
Jacek Avatar asked Feb 11 '23 11:02

Jacek


1 Answers

Your migration will need to add col to B, then use raw SQL to update B from A, then drop col from A.

AddColumn("B", "col", c => c...);
Sql("update B set col = ...");
DropColumn("A", "col");
like image 139
Craig W. Avatar answered Feb 13 '23 02:02

Craig W.