问题
My User migration used to look like this:
class CreateUsers < ActiveRecord::Migration
def change
create_table :users do |t|
t.string :login
etc
Now it looks like this:
class CreateUsers < ActiveRecord::Migration
def change
create_table :users do |t|
t.string :username
etc
Why, then, do I see this?
rake db:drop
rake db:create
rake db:migrate
rails console
> User.new
+----+-------+------------------+---------------+-------------------+------------+------------+
| id | login | crypted_password | password_salt | persistence_token | created_at | updated_at |
+----+-------+------------------+---------------+-------------------+------------+------------+
| | | | | | | |
+----+-------+------------------+---------------+-------------------+------------+------------+
1 row in set
I am using PostgreSQL.
回答1:
Incrementing the filename of the User migration solved the problem. I presume Rails was caching the contents of the migration when I tried to change its contents without changing the filename.
来源:https://stackoverflow.com/questions/12968315/rake-dbdrop-not-clearing-out-my-old-tables