Hi, guys
I fix the db/schema.rb file, and want to update the database using it .
How i should do. i try ‘rake db:migrate’ but it not works.
thanks for helps.
Hi, guys
I fix the db/schema.rb file, and want to update the database using it .
How i should do. i try ‘rake db:migrate’ but it not works.
thanks for helps.
On 20 August 2011 15:53, coolesting [email protected] wrote:
Hi, guys
I fix the db/schema.rb file, and want to update the database using it .
How i should do. i try ‘rake db:migrate’ but it not works.
You should not manually change schema.rb, you should instead write a
migration to change the database design. Running the migration will
update schema.rb.
See the Rails Guide on Migrations for how to do this.
In order to put schema.rb back to what it should be before running the
migrations you can do
rake db:schema:dump
You can alternatively just revert schema.rb using your Version Control
System. If you are not using a VCS then start doing so immediately,
you will not regret it. I prefer git.
I assume you are just getting started with Rails so have a look at all
the Rails Guides and work through some tutorials. Make sure you are
using Rails 3 and that the tutorial is for this version.
railstutorial.org is good and is free to use online.
Colin
Colin
But i still have a question, can i design a database schema for
migrating
once time. I don’t want gonna to create a migration file for some
operation
to database again and again.
Just creating a schema file for initializing the database at first.
On 21 August 2011 03:23, coolesting [email protected] wrote:
But i still have a question, can i design a database schema for migrating
once time. I don’t want gonna to create a migration file for some operation
to database again and again.
Just creating a schema file for initializing the database at first.
I don’t see why you want to write a schema manually rather than just
writing the first migration manually. It is just as easy to write the
inital migration as an initial schema. In fact the syntax is almost
identical. However, if you do want to do that then you can use rake
db:create to create the db from the schema. Note that this is not the
question you asked originally, which was how to update the db from an
updated schema. rake db:create creates a new database rather than
modifying an existing one. A migration will modify an existing data
without destroying existing data.
Colin
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.
Sponsor our Newsletter | Privacy Policy | Terms of Service | Remote Ruby Jobs