简体   繁体   中英

ActiveRecord::StatementInvalid — Mysql2::Error: Table 'database.table_that_I_want_to_create' doesn't exist

I'm trying to perform a:

rake db:migrate RAILS_ENV=production

(in this migration there are 5 files of migrations, including the creation of the table database.table_that_I_want_to_create )

And I encounter the following error:

Error message:
Mysql2::Error: Table 'database.table_that_I_want_to_create' doesn't exist: SHOW FULL FIELDS FROM `table_that_I_want_to_create` (ActiveRecord::StatementInvalid)
Exception class:
ActiveRecord::StatementInvalid

The first line of stack is:

0   /usr/local/lib/ruby/gems/1.9.1/gems/activerecord-3.2.11/lib/active_record/connection_adapters/abstract_mysql_adapter.rb 245 in `query'

abstract_mysql_adapter.rb   245
=> log(sql, name) { @connection.query(sql) }

Does anyone have an idea ?

Thanks very much

I finally understood what the problem was: - I had in an initializer file, an instantiation of a global variable: $MY_GLOBAL_VARIABLE = TableThatIWantToCreate.find(1)

I understand that when we invoke 'rake db:migrate', rails launches the context of the application (including the initializer files) before executing the migration. In my case the instantiation remained impossible because the table used for this instantiation did not already exist.

Thank for those who have a look on my problem. :-)

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM