Search code examples
rubyactiverecordmigrationsinatra

Can't generate schema.rb file with ActiveRecord


When I run 'rake db:migrate' it won't generate the schema.rb file. I ran almost every rake command already but it didn't change anything yet. Anyone, please? I'm still pretty new at this. Here are some files that may be helpful:

My Gemfile:


source "http://rubygems.org"

gem "sinatra"
gem "activerecord", :require => "active_record"
gem "sinatra-activerecord", :require => "sinatra/activerecord"
gem "rake"
gem "require_all"
gem "sqlite3"
gem "thin"
gem "shotgun"
gem "pry"
gem "bcrypt"
gem "tux"

group :test do
  gem "rspec"
  gem "capybara"
  gem "rack-test"
  gem "database_cleaner", git: "https://github.com/bmabey/database_cleaner.git"
end

One of my created migrations:

class CreateUsers < ActiveRecord::Migration
  def change
    t.string :name
    t.string :email
    t.string :password_digest
  end
end

environment.rb:

ENV['SINATRA_ENV'] ||= "development"

require 'bundler/setup'
Bundler.require(:default, ENV['SINATRA_ENV'])

ActiveRecord::Base.establish_connection(
  :adapter => "sqlite3",
  :database => "db/#{ENV['SINATRA_ENV']}.sqlite"
)

require './app/controllers/application_controller'
require_all 'app'

Solution

  • Try specifying your ActiveRecord to version 5.2 on your Gemfile, since you're using that Ruby version. Also, make sure you include it on your generated migrations.

    So on your case:

    class CreateUsers < ActiveRecord::Migration[5.2]