Reputation: 3500
How can I add a database to my SQLite3 database? I always get this error.
ActiveRecord::StatementInvalid in Timespans#index
Showing C:/xampp/htdocs/fluxcapacitor/app/views/timespans/index.html.erb where line #19 raised:
SQLite3::SQLException: no such table: timespans: SELECT "timespans".* FROM "timespans"
I tried adding my table to myschema.rb
, but it doesn't work. It is always overwritten, when I run
rake db:migrate RAILS_ENV=development
Upvotes: 0
Views: 210
Reputation: 20125
You want to use migrations to make changes to your database. See the Active Record Migrations guide for the details.
Generally speaking, the process is something like:
rails generate migration create_timespans
generates an empty migration for you.schema.rb
.rake db:migrate
then applies those changes to the database.Upvotes: 2
Reputation: 51151
You should generate migration:
bundle exec rails g migration create_timespans
And in the migration, you should have:
class CreateTimespans < ActiveRecord::Migration
def change
create_table :timespans
t.string :column1
t.string :column2
# ...
end
end
end
And run it with bundle exec rake db:migrate
.
This is the proper way to make changes in your DB schema in Rails application.
Upvotes: 3