Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to run schema.rb?

I'm trying to run db:migrate. This fails however because one of the tables that one of the migrations is trying to update does not exist. I searched the codebase and this table is created in db/schema.rb.

How can I run schema.rb before db:migrate??

like image 646
Ramy Avatar asked Jan 11 '12 16:01

Ramy


People also ask

What is schema RB?

The schema. rb serves mainly two purposes: It documents the final current state of the database schema. Often, especially when you have more than a couple of migrations, it's hard to deduce the schema just from the migrations alone. With a present schema.

How do you regenerate a schema RB?

If you run a rake -T it will list all possible rake tasks for your Rails project. One of them is db:schema:dump which will recreate the schema.

Should you commit schema RB?

You are doing only a big mistake that you can correct quickly: you should really commit the file db/schema. rb in your repository. This is standard for rails application.


1 Answers

Use the schema load task:

rake db:schema:load

From rake -T (expurgated version):

rake db:schema:dump  # Create db/schema.rb file usable with any AR-supported DB
rake db:schema:load  # Load schema.rb file into DB
like image 94
Dave Newton Avatar answered Oct 12 '22 11:10

Dave Newton