lundi 17 octobre 2022

unable to rake db:migrate

everyone one I am working on a Sinatra app. I am trying to use Active Record as my database option. This is my first time of using Active Record with Sinatra.

I have successfully created my table, but I am getting an error whenever I try to "rake db:migrate".

I have gone through likely issues I found on Stack overflow, but not getting any headway. Any help would be appreciated.

Error message for "rake db:migrate

rake aborted!
ActiveRecord::ConnectionNotEstablished: ActiveRecord::ConnectionNotEstablished

Tasks: TOP => db:migrate
(See full trace by running task with --trace)

Below is my Rakefile

require_relative './app/controllers/recipe_controller'
require 'sinatra/activerecord/rake'
task :console do
    Pry.start
end

Below is my config/environment file

require 'bundler'
require 'bundler/setup'
Bundler.require

ActiveRecord::Base.establish_connection(
  adapter: 'sqlite3',
  database: 'db/development.sqlite'
)

require './app/controllers/recipe_controller'

Below is config.ru file

require "sinatra"

require './app/controllers/recipe_controller'

run RecipeController

my create_recipes file

class CreateRecipes < ActiveRecord::Migration[7.0]
  def change
    create_table :recipes do |t|
      t.string :name
      t.text :description
      t.boolean :completed

      t.timestamps
  end
end

Aucun commentaire:

Enregistrer un commentaire