rails: `rails db:drop:all db:create:all db:migrate` isn't creating tables after adding InternalMetadata/EnvironmentMismatchError
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: d70c68d76abcbc24ef0e56b7a7b580d0013255dd f6628adc11e2e57db75030fca9bae035be5cd95b c1a1595740b243bed02f5e59090cc58dac77bbf3 de2cb20117af68cef4126d8998cc63e178c58187 302e92359cc88258ae15a82454c58408a4b8157e a76c4233a9ee9ffbf413c4b8353e73e8ffbeb3a5 350ae6cdc1ea83e21c23abd10e7e99c9a0bbdbd2 ab40d71ff88f99ee4219747fcc8774514ec50ef8 7b065f623f2a56d74eca88ed27970c71a76f0a17 921997675258147fdc2bbbca0da4fb0c771c218d 30391e9ddba745d6bdc0b23f526ecf432dfe6adf 900bfd94a9c3c45484d88aa69071b7a52c5b04b4 34ac8a1e98e85b28fe3ee02a83c85cdaa4b77714 We cannot bisect more!
cc @schneems
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Reactions: 1
- Comments: 40 (26 by maintainers)
I found a solution for myself. Here we go:
I was encountering
ActiveRecord::NoEnvironmentInSchemaError
with pg and started inspecting my databases.The key difference I found was my
ar_internal_metadata
had the columnkey
set as integer on DBs having issues and DBs not having issueskey
was set tovarchar
and had a value ofenvironment
Also my schema which was loading was doing this:
The schema should be like:
Now everything works. Hope this helps others. I’m guessing it got screwed up some how in the rails4 to rail5 migration.
app:update
task (that should be run after upgrade, according to the guide) deals with it. AFAIU it is intended behavior.@andrewyoo that schema difference was the cause of my issue as well. I deleted that table manually and re-ran
rails db:migrate
and it resolved itself. Sounds like this issue might need to re-open?@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:
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
rails new
app with Rails 5 pointing at master in the Gemfile.This command also works:
I’m thinking there’s some strange interaction with the
:all
invocations.It will be helpful if someone will write how you’ve got wrong column type in schema.
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
bin/rails db:migrate
. The normal behavior resumed and the errors were no more.