How do I go up to a specific database version from an empty database in rails?
in my case, I did reset the whole database recently, so all tables have been already dropped.
my migration files are as follows:
20111127152636_create_users.rb
20120110100458_create_cars.rb
20120131003026_add_birth_date_to_users.rb
what command do I have to call to get me the second latest version, which is 20120110100458 ?
I have tried "rake db:migrate:up version=20120110100458".
unfortunately, it didn't get me the result I expected it should be; no tables were created at all.
If you want to run the 2 first migrations, use
rake db:migrate VERSION=20120110100458
(it will run 20111127152636_create_users.rb and 20120110100458_create_cars.rb)
Related
Hi every body I'm learning Symfony 5, on migrations lessons, after a lot of make:migration commands, this time I've this messageenter image description here
And on doctrine:migrations:migrate command, I've this error
enter image description here
But in my migrations file , there's a migration with create etudiant table.
So I'll know how to run that one migration for having that table in my database, Thanks!
This Error often happened when you got some differents between the last migration file and your BDD.
First of all your script seems to drop 'etudiant' table but this one does not exist. May be you have drop it before.
However you have many possibility :
You can delete all migration file on your symfony project (under migrations folder), then delete all sql entry on doctrine_migration_versions.
After that you can redo your migration command line (make:migration and doctrine:migrations:migrate).
You can edit the last migration file on your symfony projet and delete the drop table in trouble.
i'm tying to install my ruby on rails application on a new Server.
In the folder db theres is my schema.rb file.
But my problem ist how to run the schema.rb file to run the sql statements?
You can do this:
rake db:create to create your DB (you do this only once)
rake db:migrate to migrate your BD (do this the first time and every time you want to apply changes, like removing a column)
And
rake db:seed to populate your DB, if you have something in you seeds.rb file
The schema file doesn't populate the data, rather it shows the structure of the database. You'll have to run:
rake:db:create
rake:db:migrate
on the new server and then create a dump of the data you wish to import to the new database. Then import the data. Both of these processes can differ widely depending on what kind of database you're using.
For MySQL:
Export and Import all MySQL databases at one time
For PostgreSQL:
import sql dump into postgresql database
I keep getting an error using the bqcommand line tool. For example, I can easily run this query and it returns the table that I want:
head -n 10 xxxx-bq:name_name.Report2
Note that xxxx-bq is the projectid, and name_name is the dataset id. When I try to run a query against this table, say the follwing:
query "SELECT count(*) FROM xxxx-bq:name_name.Report2
I get an error that says that I cannot start a job without a project id. What am I doing wrong here? How can I specify in the query the project ID? I know people have asked some similar questions. That said, I have been following along and my approach is not working.
Do you have a project id? If not, this page can help you set one up: https://developers.google.com/bigquery/bq-command-line-tool-quickstart
All BigQuery jobs (which include queries) require a project id, which is the project that gets billed for any damage done by the job. (by damage, I mean work)
You should either set your default project id (you can do this by running bq init)
or set the project id that you're running the job under via --project_id=
So if you're running bq shell, you would use bq shell --project_id=myprojectid instead.
strange... I just started working with bq & got the same error but it didn't like me passing --project_id=[myprojectid]. Although I was already authed with gcloud auth login, I had to run bq init (and it seemingly didn't do anything) -- after that, my queries worked just fine.
I have a minor issue which force me to introduce a new migration in between two migrations.
Short version of my question is: whether it is safe to introduce a new migration between previous two.
What I did
I need to have a table which will be filled from a file.
I added a table then imported data on the table by two migrations:
A migration which create a table with named ID column by using self.primary_key = some_id
A migration to import text data onto the table
The issue was, I forgot to add :id => false to the first migration. This cause id column to be created but haven't set correctly. Since I have primary key in some_id it does not cause problem up to now.
Rails 3.2.4
Now, I upgraded to Rails 3.2.4. Due to the change, it look like I need to set unique id before save. Which cause migration 2 above to fail.
The easiest fix is removing id column between above two migrations because I need test suite to build the database from scratch time to time. To make the import to work, I need to fix it before 2nd migration run.
Question
Now the question.
Since above migrations are deployed already, The migration will run after all of the migrations other than the one.
In my case, it looks like Ok to create such a migration (with timestamp in between above two).
Is it okay to do add migration like this way, in this case?
It might be convenient to put all the lines we type inside of bash to create the whole initial project inside a script, for all the scaffold creations, rake db:migrate, and even the git commands, so that if we ever need to create the same project under Rails 4 or 5, that will be very simple.
But for a migration file that adds index to a table column, is there a way to specify that on the command line or somehow automate that on the command line? Otherwise we will need to put in the command for the migration file creation and then manually edit that file by hand -- if everything can be put in a script, that can be kind of neat.
(or if the index can be specified in the scaffold line, that might be even better)
When generating your model's migration, use index after the field name for a regular index and uniq for a unique index.
Example:
$rails g resource Widget name:index part_number:uniq
You can probably do something similar when generating just a migration