Sinatra project with corneal gem and sqlite. Rake db:migrate not working. Schema created but cant make test data

176 Views Asked by At

Ive set this Sinatra "todo" project up using the corneal gem and sqlite. Ive created migrations and run rake db:migrate and can see the appropriate files, like a schema and development/ test db files have been made. However, when i drop into the console and try to look for "users.all" or create a user I cant proceed. Especially when running User.create(...), the returned error says -- ActiveRecord::StatementInvalid: Could not find table 'users' from /Users/dwightnodolf/.rvm/gems/ruby-2.6.1/gems/activerecord-6.1.3.1/lib/active_record/connection_adapters/sqlite3_adapter.rb:346:in `table_structure' -- When I try to drop the db to re-migrate I get this error -- Database'db/development.sqlite3' doesnot exist Database 'db/test.sqlite3' does not exist. -- No clues popping out reading the docs, and not a ton of similar issues on Stack, at least on how to make these things line up.

1

There are 1 best solutions below

1
Antonin a On

I had the same issue, in particular about your first part of question. I'm referring to:

Especially when running User.create(...), the returned error says -- ActiveRecord::StatementInvalid: Could not find table 'users' from

For this specific part of your problem, I went through the activerecord sinatra documentation sinatra doc

And as explained I've added in my file main app register Sinatra::ActiveRecordExtension

After this, I was able to access to the table, write read...