Am I correct in saying that the db/schema.rb file should be pulling from the db/migrate files on rake db:migrate? I am running a rake db:migrate and it is adding a table that isn't defined in the migrate, nor the models. Any ideas?
Migrate Files (just one):
class CreateUsers < ActiveRecord::Migration
def change
create_table :users do |t|
t.string :email
t.string :hashed_password
t.timestamps
end
end
end
Resulting Schema after rake:
ActiveRecord::Schema.define(:version => 20121113214159) do
create_table "user_categories", :force => true do |t|
t.string "title"
t.string "description"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
create_table "users", :force => true do |t|
t.string "email"
t.string "hashed_password"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
end
I had added a user_categories scaffolding earlier, but incorrectly so I destroyed it. Not sure where I went wrong in destroying parts...
If you don't have any important data on your db, you could run rake db:drop
then rake db:create
. Then run rake db:migrate
and it should update your schema clean.
It's important to note that rake db:migrate
will poll your database for its current state (separate of migrations) and update schema.rb accordingly. If you go into SQL command line and add a table, for example, and then run rake db:migrate
, schema.rb will reflect that new table whether there's a migration or not.
Could be that your forgot to define environment variables.
Gemfile
and verify that you don't use the sqlite
gem for your environment rake db:drop
then rake db:drop
commands if as output you receive empty string probably you forgot to setup environment variables config/database.yml
file and find places where you could use them. You should find something like that: database: <%= ENV["<DB_NAME"] %>
dotenv
or figaro
gems, probably you forgot to create appropriate file or define variables there
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.