What's wrong with my primary keys?

I am using rails 2.3.4

When I execute rake db: test: preparing the generated id field is not the primary key and is automatically incremented.

When I look at db development without primary key issues.

Using MySQL.

Edit: it looks like my schema.rb file has been modified: id => false should be true. What generates this file? DB Migrations?

[EDIT] What is the actual mechanics for generating the schema.rb file?

+2


source to share


3 answers


When you run rake tasks, tasks run on the default environment if no environment is specified.

You probably have different versions of the schemas between your test and development bases.

rake db:reset #drops and created the database for current environment
rake db:reset:all #drops and creates database for all environments
rake db:migrate #migrates the schema for the current environment
rake db:migrate RAILS_ENV=test #migrates the schema for the test environment

      



If I'm not mistaken (as I remember now)

rake db:migrate #applies the migrations and dumps the schema to db/schema.rb file
rake db:schema:dump #dumps the actual state of your current environment schema into db/schema.rb file

      

+1


source


Hey, I looked at this question yesterday and saw that no one has answered yet, so I'll try to help, to be honest, I don't know exactly why this is mostly happening as I didn't really use the "prepare" task. When running the migration from schema.rb is created with an empty database.



I usually run db: test: clone whenever changes have been made to this schema, this will ensure that your test database always matches your current environments. Maybe try dropping the database and recreating it from your migrations and then running the clone. After that, the schema still shows: id => false? If so, you can post your migration, which creates the appropriate table.

+1


source


If you use 'reset' then 'db: test: prepare' you will most likely get the result you want. For example:

rake db:reset
rake db:test:prepare

      

It will be:

  • recreate the dev database based on your latest migrations.
  • recreate the schema.rb file based on migrations / dev database
  • recreate the test database based on the schema.rb file.
+1


source







All Articles