How do I run migrations for a specific environment in laravel

后端 未结 4 1193
忘了有多久
忘了有多久 2021-02-05 04:57

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          


        
相关标签:
4条回答
  • 2021-02-05 05:35

    I figured out a solution to run migrate for different databases. Basically, the command artisan migrate --env=local doesn't work. But we can define a new connection string in config\database.php. For example:

    <?php
       'mysql_testing' => [
            'driver'    => 'mysql',
            'host'      => env('DB_TESTING_HOST'),
            'database'  => env('DB_TESTING_DATABASE'),
            'username'  => env('DB_TESTING_USERNAME'),
            'password'  => env('DB_TESTING_PASSWORD'),
            'charset'   => 'utf8',
            'collation' => 'utf8_unicode_ci',
            'prefix'    => 'prefix_',
        ],
    

    And specify the --database when we run artisan migrate like this:

    php artisan migrate --database=mysql_testing
    

    Hope this helps :)

    0 讨论(0)
  • 2021-02-05 05:38

    You need to specify the environment before the migrate command.

    artisan --env=local migrate
    

    Running artisan help shows you the format in which commands are to follow.

    artisan help
    
    Usage:
      [options] command [arguments]
    
    0 讨论(0)
  • 2021-02-05 05:40

    If you modify a migration after running it, you first need to rollback the migration.

    php artisan migrate:rollback
    

    Keep running that until the migration you've changed is rolled back. Alternatively, you can reset your entire schema with

    php artisan migrate:reset
    

    But you will then need to call your migrations like normal to bring them up to date.

    php artisan migrate
    

    Finally you can reset and then migrate by calling

    php artisan rebuild
    

    Also note that it is generally bad practice to modify your migrations after they have been made, unless you literally just made it. Once it is deployed you should not modify it, and instead create a new migration file.

    Hope this helps.

    Edit: I somehow missed the Laravel 4 indicator. Most of these commands still work I believe, but you may need to adjust.

    0 讨论(0)
  • 2021-02-05 05:59

    Resolved.

    Solution was simply to edit the local/database.php (or production/database.php etc), making sure that the migrations path variable is pointing to the location that migrate:make is creating the migration files, just change

    'application' => __DIR__.'/../database/migrations',
    

    to

    'application' => DIR.'/../../database/migrations',
    
    0 讨论(0)
提交回复
热议问题