You would like to run a migration in a symfony 2x project either up or down.
You can run the following for getting a migration up or down:
php app/console doctrine:migrations:execute 20171020125225 --up
php app/console doctrine:migrations:execute 20171020125225 --down
In your rails project very often, after creating a new migration, you have to run the migration in the development database and then in the test database.
A neat way to combine both these steps as one, taken from the book Rails 4 in Action, is to create an alias in your ~/.bashrc configuration file with the following, so that you only have to run migrate after each migration that would apply the migration in both development and test databases:
alias migrate='bin/rake db:migrate && bin/rake db:test:prepare'
You have a rails application with many migrations build over time and you want to recreate the database from start. Should you be using the normal way of running the migrations (db:migrate) or the one that loads the actual schema to the database (db:schema:load).
According to the book Rails 4 in Action (MEAP v9 page 146) :
The bin/rake db:migrate task runs the migrations and then dumps the structure of the database to a file called db/schema.rb. This structure allows you to restore your database using the bin/rake db:schema:load task if you wish, which is better than running all the migrations on a large project again! NOTE
NOTE: Large projects can have hundreds of migrations, which may not run due to changes in the system over time. It’s best to just use the bin/rake db:schema:load.
You want to run the rails model generator to create a new model, but you don’t want the migration for that model as it could be included in another migration (ie grouped together with other tables).
Just run the generator with the –migration=false option as in:
rails g model ModelName --migration=false
To get used to the new ways of working with Rails 2.
Here are some of the new ways of doing things in Rails 2.
- Create a scaffold and migration on one step:
./script/generate scaffold product fied1_name:string field2_name:string field3_name:float
Make sure that you don’t have any previous migration(ie manually created) for the same model, as the generator will stop and won’t overwrite the previous migration.
When using cap deploy_with_migrations, the default behaviour is to deploy with the migrations in the production environment.
To change this behavior add:
set :rails_env, "development"
in your config/deploy.rb
After spending some time trying to make a migration work, and having the error message coming back:
You have a nil object when you didn't expect it!
You might have expected an instance of Array.
The error occurred while evaluating nil.
I’ve decided to do a google search for the specific problem, as it was working fine with other test migrations.
It turns out that if the migration is not model specific, but a different one (ie trying to add a new column to an existing table), the :int for the column doesn’t work!
It has to be :integer.
Full bug report and the article are here:
Migrations: :integer works, :int doesn’t – datatype discrepancy