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
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 :)
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]
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.
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',