laravel PHP artisan migrate:refresh 是从数据库中删除所有现有数据

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/29293788/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 11:14:17  来源:igfitidea点击:

PHP artisan migrate:refresh is delete all present data from database

phplaravellaravel-5

提问by Dipesh Shihora

If I use the PHP artisan migrate:refreshcommand, it deletes my old data from other tables every time.

如果我使用 PHP artisanmigrate:refresh命令,它每次都会从其他表中删除我的旧数据。

What should I do for that so that my migrate is run successfully and my old data is not erased?

我该怎么做才能使我的迁移成功运行并且我的旧数据不会被删除?

回答by Laurence

This is the expected behavior.

这是预期的行为。

Migrate refresh will remove all tables, then reinstall all migrations. So any data will be lost.

迁移刷新将删除所有表,然后重新安装所有迁移。所以任何数据都会丢失。

If you want to add further migrations to your current database - you should just be running php artisan migrate- which will only run migrations that have not yet occurred.

如果您想向当前数据库添加更多迁移 - 您应该只是运行php artisan migrate- 它只会运行尚未发生的迁移。

回答by Amon Bazongo

If you want to change your database but you dont want your old data to be erase, you have to add your database modification through another migration file. For example, if you want to add a field to a table (let's say add 'address' field to 'users' table) which already has some data, you first create a migration like php artisan make:migration add_address_to_users. And in the created file, you just add a column in the table like this.

如果您想更改数据库但又不想删除旧数据,则必须通过另一个迁移文件添加数据库修改。例如,如果您想将一个字段添加到已经有一些数据的表中(假设将“地址”字段添加到“用户”表中),您首先要创建一个像php artisan make:migration add_address_to_users. 在创建的文件中,您只需像这样在表中添加一列。

Schema::table('users', function($table){ $table->string('address'); });

Schema::table('users', function($table){ $table->string('address'); });

And on the command line, you just type php artisan migrate. You will see that your data will not be erased and the new field has been added

在命令行上,您只需键入php artisan migrate. 您将看到您的数据不会被删除并且新字段已添加

回答by Daya

Yes, This is the expected behavior of this command. If you want to run only perticular table then,

是的,这是此命令的预期行为。如果你只想运行特定的表,那么

Copy your migration file to a temporal folder "temp" in migrations folder, then run (paths as in L5):

将迁移文件复制到迁移文件夹中的临时文件夹“temp”,然后运行(路径如 L5):

php artisan migrate --path=database/migrations/temp

php artisan migrate --path=database/migrations/temp

This way it will only run that file without messing with your current tables.

这样它只会运行该文件而不会弄乱您当前的表。

回答by Vinod Kumar

Delete the single table which is already created using previous migration also delete the migration name from migrations table, then your migration will execute without deleting the record.

删除已使用先前迁移创建的单个表,同时从迁移表中删除迁移名称,然后您的迁移将在不删除记录的情况下执行。