[英]laravel 8 migration deletes worldcities table
I have a table called worldcities that has all the cities on this pl.net, but everytime I migrate:fresh --seed then all tables are deleted including this one.我有一个名为 worldcities 的表,其中包含此 pl.net 上的所有城市,但每次我 migrate:fresh --seed 然后所有表都被删除,包括这个。 Also, it takes forever to put the cities back since it's about 1gb.此外,由于它大约为 1 GB,因此将城市恢复原状需要很长时间。
What would be the best way to use php artisan migrate:fresh --seed without also deleting the worldcities table?在不删除 worldcities 表的情况下使用php artisan migrate:fresh --seed的最佳方法是什么? I have tried many options, but none is working yet.我尝试了很多选择,但都没有奏效。
I read something about --ignore=worldcities, but that doesn't work with fresh.我读了一些关于 --ignore=worldcities 的内容,但这不适用于 fresh。 So it's not taking me anywhere this far.所以它不会带我到任何地方。
Instead of using migrate:fresh
you can use migrate:refresh
, which uses down()
method of the migration.您可以使用migrate:refresh
代替migrate:fresh
,它使用迁移的down()
方法。
So in down
method comment dropping table: Schema::dropIfExists()
,所以在down
方法注释删除表中: Schema::dropIfExists()
,
Then in up
method, check that table is already exists or not:然后在up
方法中,检查表是否已经存在:
if (Schema::hasTable('table_name')) {
return;
}
For seeding simply check that record exists or not, for preventing duplication.对于播种,只需检查记录是否存在,以防止重复。 Or for fewer query, just create if table doesn't have any records.或者对于更少的查询,如果表没有任何记录就创建。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.