lorint / brick

Auto-generate models, views, controllers, and routes in a Rails app based on database structure
Other
269 stars 8 forks source link

"NoMethodError: undefined method `tr' for nil:NilClass" when running "rake db:create" #3

Closed Imitat closed 1 year ago

Imitat commented 1 year ago

Hi, mentioning that in a brand new Rails 7 application (gem "rails", "~> 7.0.4", ">= 7.0.4.2") w/ gem 'brick' in the Gemfile , I'm seeing the below when running rake db:create (or rails db:create). Commenting Brick and re-running doesn't produce the error. Best!

j@js-MacBook:~/Sites/git/automodels$ rake db:create --trace
** Invoke db:create (first_time)
** Invoke db:load_config (first_time)
** Invoke environment (first_time)
** Execute environment
** Execute db:load_config
** Execute db:create
undefined method `tr' for nil:NilClass
Did you mean?  try
Couldn't create 'automodels_development' database. Please check your configuration.
rake aborted!
NoMethodError: undefined method `tr' for nil:NilClass
Did you mean?  try
/Users/j/.rvm/gems/ruby-3.0.3/gems/brick-1.0.117/lib/brick/extensions.rb:2388:in `retrieve_schema_and_tables'
/Users/j/.rvm/gems/ruby-3.0.3/gems/brick-1.0.117/lib/brick/extensions.rb:2194:in `_brick_reflect_tables'
/Users/j/.rvm/gems/ruby-3.0.3/gems/brick-1.0.117/lib/brick/extensions.rb:2012:in `establish_connection'
/Users/j/.rvm/gems/ruby-3.0.3/gems/activerecord-7.0.4.2/lib/active_record/tasks/mysql_database_tasks.rb:8:in `establish_connection'
/Users/j/.rvm/gems/ruby-3.0.3/gems/activerecord-7.0.4.2/lib/active_record/tasks/mysql_database_tasks.rb:20:in `create'
/Users/j/.rvm/gems/ruby-3.0.3/gems/activerecord-7.0.4.2/lib/active_record/tasks/database_tasks.rb:122:in `create'
/Users/j/.rvm/gems/ruby-3.0.3/gems/activerecord-7.0.4.2/lib/active_record/tasks/database_tasks.rb:184:in `block in create_current'
/Users/j/.rvm/gems/ruby-3.0.3/gems/activerecord-7.0.4.2/lib/active_record/tasks/database_tasks.rb:557:in `block (2 levels) in each_current_configuration'
/Users/j/.rvm/gems/ruby-3.0.3/gems/activerecord-7.0.4.2/lib/active_record/tasks/database_tasks.rb:554:in `each'
/Users/j/.rvm/gems/ruby-3.0.3/gems/activerecord-7.0.4.2/lib/active_record/tasks/database_tasks.rb:554:in `block in each_current_configuration'
/Users/j/.rvm/gems/ruby-3.0.3/gems/activerecord-7.0.4.2/lib/active_record/tasks/database_tasks.rb:553:in `each'
/Users/j/.rvm/gems/ruby-3.0.3/gems/activerecord-7.0.4.2/lib/active_record/tasks/database_tasks.rb:553:in `each_current_configuration'
/Users/j/.rvm/gems/ruby-3.0.3/gems/activerecord-7.0.4.2/lib/active_record/tasks/database_tasks.rb:184:in `create_current'
/Users/j/.rvm/gems/ruby-3.0.3/gems/activerecord-7.0.4.2/lib/active_record/railties/databases.rake:45:in `block (2 levels) in <main>'
/Users/j/.rvm/gems/ruby-3.0.3/gems/rake-13.0.6/lib/rake/task.rb:281:in `block in execute'
/Users/j/.rvm/gems/ruby-3.0.3/gems/rake-13.0.6/lib/rake/task.rb:281:in `each'
/Users/j/.rvm/gems/ruby-3.0.3/gems/rake-13.0.6/lib/rake/task.rb:281:in `execute'
/Users/j/.rvm/gems/ruby-3.0.3/gems/rake-13.0.6/lib/rake/task.rb:219:in `block in invoke_with_call_chain'
/Users/j/.rvm/gems/ruby-3.0.3/gems/rake-13.0.6/lib/rake/task.rb:199:in `synchronize'
/Users/j/.rvm/gems/ruby-3.0.3/gems/rake-13.0.6/lib/rake/task.rb:199:in `invoke_with_call_chain'
/Users/j/.rvm/gems/ruby-3.0.3/gems/rake-13.0.6/lib/rake/task.rb:188:in `invoke'
/Users/j/.rvm/gems/ruby-3.0.3/gems/rake-13.0.6/lib/rake/application.rb:160:in `invoke_task'
/Users/j/.rvm/gems/ruby-3.0.3/gems/rake-13.0.6/lib/rake/application.rb:116:in `block (2 levels) in top_level'
/Users/j/.rvm/gems/ruby-3.0.3/gems/rake-13.0.6/lib/rake/application.rb:116:in `each'
/Users/j/.rvm/gems/ruby-3.0.3/gems/rake-13.0.6/lib/rake/application.rb:116:in `block in top_level'
/Users/j/.rvm/gems/ruby-3.0.3/gems/rake-13.0.6/lib/rake/application.rb:125:in `run_with_threads'
/Users/j/.rvm/gems/ruby-3.0.3/gems/rake-13.0.6/lib/rake/application.rb:110:in `top_level'
/Users/j/.rvm/gems/ruby-3.0.3/gems/rake-13.0.6/lib/rake/application.rb:83:in `block in run'
/Users/j/.rvm/gems/ruby-3.0.3/gems/rake-13.0.6/lib/rake/application.rb:186:in `standard_exception_handling'
/Users/j/.rvm/gems/ruby-3.0.3/gems/rake-13.0.6/lib/rake/application.rb:80:in `run'
/Users/j/.rvm/gems/ruby-3.0.3/gems/rake-13.0.6/exe/rake:27:in `<top (required)>'
/Users/j/.rvm/gems/ruby-3.0.3/bin/rake:25:in `load'
/Users/j/.rvm/gems/ruby-3.0.3/bin/rake:25:in `<main>'
/Users/j/.rvm/gems/ruby-3.0.3/bin/ruby_executable_hooks:22:in `eval'
/Users/j/.rvm/gems/ruby-3.0.3/bin/ruby_executable_hooks:22:in `<main>'
Tasks: TOP => db:create
Imitat commented 1 year ago

Apologies, I resolved this and it's an issue local to me. Please feel free to delete this and thanks for the interesting code!

lorint commented 1 year ago

I resolved this and it's an issue local to me

Do you know what -- I had been trying to recreate what you describe with Sqlite and Postgres, and just no luck, and then ... when I tried with a fresh MySQL then it did fail in the same way that you describe!

Screenshot 2023-03-02 at 20 19 08

So I will pursue a fix for those who have a fresh MySQL install :)

Thanks very much for reaching out -- inadvertently it's set the universe just that little bit more into alignment.

Imitat commented 1 year ago

Hi, regret I didn't mention I'm using MySQL! I am, and was about to update that I do still see the issue. Thanks for your time and again, the interesting gem.

lorint commented 1 year ago

Okay -- to fix it for the moment, run mysql -uroot and then this:

CREATE DATABASE automodels_development;
CREATE DATABASE automodels_test;
QUIT

And at that point you should be able to create migrations / do everything else normally. As well in database.yml if you wanted to point things to an existing MySQL database then that should work out pretty well, no more need to bin/rails db:... anything.

Will let you know when this fix is available -- will also bundle in the Trix editor for larger :text fields. So a couple things coming along at once for the upcoming v1.0.118.

Imitat commented 1 year ago

Excellent, thank you!

lorint commented 1 year ago

Okay, v1.0.118 has now shipped, which includes a fix for the bug that you had found. You can update your project by running:

bundle update brick

Thanks!