如何在laravel中为特定环境运行迁移 [英] How do I run migrations for a specific environment in laravel
问题描述
我正在使用laravel(Laravel 4)建立一个新应用,并且在通过迁移设置数据库时遇到一些问题.
I'm setting up a new app with laravel (Laravel 4), and having some issues setting up the database via migrations.
我通过以下方式制作了迁移文件:
I made a migration file with:
artisan migrate:make --table="jobs" --create jobs
如期在数据库/迁移中创建了一个文件,我对此做了一些修改,然后使用
Which created a file in database/migrations as expected, I made some mods to this, and went to fire it up using
artisan migrate --env=local
但是我得到了"Nothing to migrate"
如果我尝试在不使用--env=local
的情况下运行,它将使用我们不想使用的config文件夹(而不是本地/staging/production文件夹中)中的database.php,因为它不是特定于环境的
If I try run without --env=local
, it uses the database.php in the config folder (not in the local / staging / production folder) which we don't want to use, as it won't be environment specific.
我的第一个想法是好的,也许我需要在migrate:make
调用上放置env标志,所以我尝试了一下,但是收到一条错误消息,说它无法创建迁移文件.然后,我认为无论如何进行基于环境的迁移都是没有意义的……应该将它们创建为通用类型,并简单地在每个环境中运行,因此最后,所有环境都使用相同的迁移脚本.
My first thought was OK, maybe I need to put the env flag on the migrate:make
call, so I tried that, but got an error saying it couldn't create the migration file. Then I thought it doesn't make sense to make env based migrations anyway... they should be created generic, and simply run on a per env basis, so in the end, all environments are using the same migration scripts.
所以我现在对从这里去哪里很困惑
So I'm a bit stuck now on where to go to from here
推荐答案
您需要在迁移命令之前指定环境.
You need to specify the environment before the migrate command.
artisan --env=local migrate
运行artisan help
显示命令遵循的格式.
Running artisan help
shows you the format in which commands are to follow.
artisan help
Usage:
[options] command [arguments]
这篇关于如何在laravel中为特定环境运行迁移的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!