-
Notifications
You must be signed in to change notification settings - Fork 21.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
rails db:drop:all db:create:all db:migrate
isn't creating tables after adding InternalMetadata/EnvironmentMismatchError
#23279
Comments
May be we can run r? @schneems |
Confirmed this issue on master. |
Are you getting any errors or output? Can you run with |
Getting this output
|
This is what I get
Though it still doesn't have tables
|
Weird that running only the
|
Getting the same as @schneems here, but saw |
You'll get that error if you're trying to run that command on a non-empty database that was upgraded from Rails 4.2. To resolve it follow directions, run that command. That error is expected, there's no way around it, running it is part of the upgrade process. I'm running off of a This command also works:
I'm thinking there's some strange interaction with the |
I am also getting same output now, in my case the database did not had anything in But now I am getting same issue from #23279 (comment) 😄 |
It works if you don't do
|
BTW I figured out a one liner to test (if you're using a SQLite3 database
|
I figured out what is going on. I added some logging to see what database we are connected to
Notice that the last database to connect is production, so let's check production
Bingo. Now there's the question of what changed to cause this behavior? The reason that
db:migrate will use that connection.
We can fix this by explicitly connecting to the "current" database at the end of Here's my guess: i'm thinking that previously AR wasn't "connected" to any database. The "create" action used in the rake task doesn't use rails/activerecord/lib/active_record/tasks/database_tasks.rb Lines 107 to 116 in cadb8af
db:migrate gets called it sees that it isn't connected to a DB, tries to connect, succeeds and then migrates the database.
My patch changed the behavior because now we have to If i'm right about the cause, then it was basically working by accident before. Any ideas @sgrif ? |
I've been thinking we should maybe explicitly do an |
Any progress on this issue? |
ping @sgrif you assigned this to yourself, do you have an idea on a fix? |
Our company is running into this same issue on our |
This issue is fixed in 5.0.0 and doesn't affect any release version of rails. |
I get this behavior (or similar) with Rails 5.0.0.1
|
@estiens Same here popped up today |
I had this problem on our CI setup, and fixed it with
|
Anyone have an example app with steps to repro the problem? I'm not exactly sure the underlying failure mode. That first command should populate the internal metadata table, and that should be all we need. I'm wondering if it's trying to drop a different database somehow. |
I was able to reproduce the error:
This is with 5.0.0 |
@vgonda : do you have an example app of this? |
I don't 😞 I was able to reproduce it in a private repo, but I haven't been able to reproduce since. |
Dang, well maybe if we summon the @group we could get someone who has an On 2 November 2016 at 17:56, Victoria Gonda notifications@github.com
|
@Schwad I came here by googling. My problem may not be the same but seems related. And I have a super-simple reproduction:
I get the following output:
|
I strangely got this error when checking out a pre Rails 5 commit in our repo, loading schema from that commit and then going back to HEAD commit with Rails 5.
Any db rake/rails command I tried to run would cause the error to be thrown (even after running the environment setup command recommended in the error). Strangely, when the one exception is when I ran |
Interesting. What do you make of this @schneems ? |
|
I am having the same issue with a bamboo and an instance of my rails 5.0.0.1 app. I already tried app:update, doesn't work. |
@tfluehmann …and you haven't provided steps to reproduce an issue. |
@ojab sorry for that, I fixed it now by running rails db:environment:set RAILS_ENV=test before each command.
instead of simply:
|
@Schwad I solved my previous reproduction by removing the pending migrations check from
The file bundle exec rake db:migrate RAILS_ENV=test
RAILS_ENV=test bundle exec rake spec # succes
bundle exec rake # succes
RAILS_ENV=test bundle exec rake spec # failure So the result of the above steps is that the specs are 'run' three times. I added a
I hope this helps getting to the root of the problem. I'm happy to open a new ticket if you feel this is a different problem. |
I found a solution for myself. Here we go: I was encountering The key difference I found was my Also my schema which was loading was doing this: create_table "ar_internal_metadata", primary_key: "key", force: :cascade do |t|
t.string "value"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end The schema should be like: create_table "ar_internal_metadata", primary_key: "key", id: :string, force: :cascade do |t|
t.string "value"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end Now everything works. Hope this helps others. I'm guessing it got screwed up some how in the rails4 to rail5 migration. |
@andrewyoo that schema difference was the cause of my issue as well. I deleted that table manually and re-ran |
It will be helpful if someone will write how you've got wrong column type in schema. |
@ojab Not sure. I had been switching between Rails 4.2 and 5.0 branches as we are upgrading to 5.0... |
@micahlisonbee @ojab I was also regularly switching between Rails 4.2 and Rails 5 branches as I was working on an upgrade when I encountered this issue -- thanks for sleuthing @andrewyoo ! |
Just to add another potential cause of |
Right now
rails db:drop:all db:create:all db:migrate
leaves DB without any tables, before adding internal metadata this command resulted in migrated DB.Unfortunately I can't bisect the issue because in many commits dropping/creating/migration in a single run is broken, but AFAICS the issue emerged after adding InternalMetadata/EnvironmentMismatchError.
The first bad commit could be any of:
d70c68d
f6628ad
c1a1595
de2cb20
302e923
a76c423
350ae6c
ab40d71
7b065f6
9219976
30391e9
900bfd9
34ac8a1
We cannot bisect more!
cc @schneems
The text was updated successfully, but these errors were encountered: