I have few migrations files.How can I run single migration down or up, if this migration isn't the newest, but some steps in the migrations history?
When I run yiic migrate up 1, it runs the latest migration. Running migration command using migration version as parameter also doesn't help.
Please check documentation about redoing-migrations section:
yiic migrate redo [step]
If you want to undo/redo only one specific migration in your migration history. You have to modify your migration history :
yiic migrate mark 101129_185401
yiic migrate redo
In Yii 1.1 - to redo just one historic migration you need a few steps.
Make a note of the full name of the latest migration you have run (the last displayed in your migrations table) and the full name of the migration you want to run again:
m210905_112345_to_run_again
m210906_125400_latest_one
Go back in time:
yiic migrate mark m210905_112345_to_run_again
Run that one migration again
yiic migrate redo 1
Go forward in time to latest
yii migrate mark m210906_125400_latest_one
For Yii 2 it should be (although I haven't tested this set of commands):
Go back in time:
yiic migrate/mark m210905_112345_to_run_again
Run that one migration again
yiic migrate/redo 1
Go forward in time to latest
yii migrate/mark m210906_125400_latest_one
Related
./psh.phar install
doing so installs required dependencies but also make fresh installation of demodata and drops the existing data. How do you continue persisting existing data and update the system locally?
There is a ./psh.phar update command, that will execute all new database migrations etc. in place, that is probably what you were looking for.
I've created a project using EF Version 6.0, with settings of AutomaticMigrationsEnabled = true;
Which worked fine, i could able to deploy in production server on first time, It created desire database tables.
Now for second update, I've get script out from migration so that i can able to run in production server. but i tried many Package Manager commands, but it does creating empty .sql files.
My second Migration has name "201601181549424_Version-1.2.0", i used following sequence of steps and commands to generate .sql file.
Added desire data classes (which will be creating tables in database) and MVC views and controller.
Run Package Manger Command is "ADD-MIGRATION Version-1.2.0" has created 201601181549424_Version-1.2.0" file in Migration folder
Than "UPDATE-DATABASE" - has updated local database, check everything works fine.
Than "UPDATE-DATABASE -Script" - has created empty.sql file. I am looking to get sql file with creation of database tables in sql file.
Can you please help me understand how i can deploy this in production database.
Thanks,
I figured out by this way..
Make desire changes to model, (INSERT OR UPDATE MODEL)
Add-Migration
Update-Database -Script
(Which will create script and can store for QA or production deployment purpose)
Update-Database
(Above command will update model in to local database)
I created a new rails 4 engine and added a model. I am trying to migrate the database using
RAILS_ENV=test rake db:migrate
and it comes back with no errors. However, when I run:
rspec spec
an error returns stating there are pending migrations.
Migrations are pending; run 'rake db:migrate RAILS_ENV=test' to resolve this issue. (ActiveRecord::PendingMigrationError)
It's true if I look at my database (tried on pg and sqlite) that they have not been run and no tables have been created. Running the suggested command listed above does not run the migrations.
There is only one migration in 'engine_name/db/migrate', and no migrations inside the dummy app.
I am using ruby 2.0 and rails 4.0.0.rc1.
You need to copy migrations into dummy app rake app:<engine_name>:install:migrations
Add code in your engine task
https://gist.github.com/doabit/5692865 .
I've experienced this same issue. doabit's fix worked for me. thanks!
There is an open issue for this with the rails core team.
https://github.com/rails/rails/issues/10622
I enabled migrations for my entity framework application. Now, i want to update my database on my remote server. I ran this command:
PM> Update-Database -Script
So it generated a sql script. But, this script has all the metadata that I actually have in my database, and not the changes that were made; so, when I try to run this sql script on my remote server, it says that tables already exists.
How can i generate sql script, that will contain only necessary updates?
You can target a specific migration for this. If you have a migration called Foo, for example:
Update-Database -TargetMigration Foo -Script
It will generate a migration script for the Foo migration. Replace Foo with whatever migration you need to run on that server.
Add-Migration InitialMigration
Add-Migration AddCustomers
Add-Migration AddProjects
Let's say you have the above three migrations in your project, and your local database has all of them applied, but the remote database only has InitialMigration. You can run the following:
Update-Database -SourceMigration InitialMigration -TargetMigration AddProjects -Script
This will apply two migrations on the remote server (AddCustomers and AddProjects).
If you have access via remote desktop to the server you can execute the command-line migration tool which is usually found in [projectFolder]/packages/EntityFramework.5.0.0/tools/migrate.exe
And call it like this:
Migrate.exe [StartupProjectName] /StartupDirectory:"[BIN folder path]" /ConnectionStringName:"[Connection String Name]" /StartupConfigurationFile:"[Path to web or app.config]"
You could use the MigrateDatabaseToLatestVersion Initializer to automatically apply any new migrations when you deploy a new version of your application:
Database.SetInitializer(new MigrateDatabaseToLatestVersion<MyDbContext, Configuration>());
I am newbie to yii. I have made database in MySQL.After that I want to migrate the database.So for that I made a folder called migration under protected and from framework folder whenever I am writing command yiic migrate create --name=add_table in terminal.It is showing error like yiic: command not found
I am using ubuntu 11.04.So what is the problem behind that.
cd down to the folder containing the yiic file and try the command then. If that doesn't work try to put "php" in front of the command like:
php yiic migrate create --name=add_table
Or you could try:
./yiic