Rails db:migrate relation does not exist
First, check your sequence of migrations. It seems that you are trying to create a reference before creating the table subject_items
itself.
You should first create students table then your subject_items table then add the reference. Or alternatively add the reference columns yourself when creating the tables which is all what add_reference
does.
Also, You have two relations from Student
to SubjectItem
.
has_many :subject_items, dependent: :destroy, through: :participations
has_many :subject_items, dependent: :destroy
You need to your first relation in order for ActiveRecord to be able to identify the correct one first for querying then for your migration. Think of the query that will be generated if you called @student.subject_items
for example. Will it go through the first relation or the second one.
Your relations should be ex:
has_many :participation_subject_items, dependent: :destroy, through: :participations
has_many :subject_items, dependent: :destroy
Cannot run rake db:migrate, relation does not exist
The Routes
file in Rails uses device_for
, which loads the User model, which in turn has acts_as_messagable
and loads the Message
class. Line #29 in Message
class says:
scope :unread, where('reciever_open = false')
The where
method is triggering a column lookup, which fails because the migrations haven't run yet! Try one of these two:
Change this to:
scope :unread, where(:reciever_open => false)
Or if that also triggers a column lookup, then say:
scope :unread, lambda { where('reciever_open = false') }
Rake db:setup does not run rails db:migrate, schema.rb does not exist error
If you check out the source code for rails db:setup
you will see that db:setup
does NOT run db:migrate
Creates the database, loads the schema, and initializes with the seed data (use db:reset to also drop the database first)
db:schema:load
loads what currently exists in your schema.rb
into the database.
heroku rake migrate db error relation post doesn't exist
I'm of the opinion that somewhere along the line one of your migrations were edited (which would be the problem if not properly rolledback first etc) and is now causing a major problem. And since you need to keep the data and can't do a full db:rollback I would say there is maybe one option I can think of unless someone else has a better idea. I never recommend editing migration files but I've had to do it in the past in certain circumstances. Do the following and make sure you keep in mind that any changes to the db can't be undone with a simplegit checkout .
I would create a new migration file by hand, not by using the rails generator and give it a timestamp that is a couple seconds before the timestamp of the Comments table migration file. I would then create the Posts table in that migration and edit the other existing migration that created the Posts table to just add it's columns. You must then go into your database (Not your rails console but your database which is probably Postgres) and insert this migration into the "schema_migrations" table. This schema_migrations table is automagically setup by rails whenever you generate a migration and run db:migrate. You'll notice the entries in this schema_migrations table are listed by "Version" where the version is the timestamp of the migration in your migration folder. You must then add the migration file timestamp to your schema_migrations table and it should be good to go.
UPDATE: IF you don't care about losing the data you can rollback all migrations, edit your migrations files and then re-run them.
bundle exec rake db:migrate:status #Look at the first version id and copy it.
bundle exec rake db:rollback VERSION=theVersionNumberYouCopiedHere
Then re check the migration statuses with the first command and make sure all migration statuses are listed as "down". This will have dropped all tables etc. Then go into your migration files and remove the referencing of your posts table from the Comments table that was giving you the issues. Then re-run all migrations again. Then add your posts_id reference to the comments table as follows by generating and running the following migration:
rails g migration AddPostToComments post:references
Looking in that migration file you should see something like this:
class AddPostToCommentss < ActiveRecord::Migration
def change
add_reference :comments, :post, index: true
add_foreign_key :comments, :posts
end
end
Now run bundle exec rake db:migrate
and you should be good to go. Commit all the changes to git and then push to heroku!
Error: Relation does not exist when running Rails in production using postgresql
The production
database created from the database.yml
file with rake db:create:all
is created locally on your machine, not on heroku.
Heroku automatically infers the database config for the production environment, and creates it when you run git push heroku master
for the first time.
The error message about posts
table not existing is because of not running migrations on heroku. Run heroku run rake db:migrate
to apply the migrations to the production database on heroku.
Also, you don't need to have the production
section of the database.yml
on your local environment.
Do refer to https://devcenter.heroku.com/articles/getting-started-with-rails4 while working for the first time with heroku; it is comprehensive and very helpful.
EDIT
The actual problem was to get the local production database to work.
Solution was to apply the migrations correctly with rake db:migrate RAILS_ENV=production
I can not create a user through the console PG::UndefinedTable: ERROR: relation team_members does not exist
There is no team_members
table on your database so you cannot create a TeamMember
.
If you would like to create this one you might run this command (for example);
rails g model TeamMember email:string
It will generate the migration file (db/migrate/20180914074925_create_team_members.rb)
and also app/models/team_member.rb
After rails db:migrate
Then you now can create it through the console
Related Topics
How to Kill a Process on No Output for Some Period of Time
How to Set Dt_Rpath or Dt_Runpath
How to Autocomplete a Bash Commandline with File Paths
I.Mx35 Suspend CPU and Ddr2 from Iram
Why Does Docker Prompt "Permission Denied" When Backing Up the Data Volume
How to Catch Stdout Stream in Ffmpeg Then Pipe It to V4L2Loopback
Question About File Seeking Position
How to Kill All Child Processes Without Killing the Parent
Calculate Mean of Each Column Ignoring Missing Data with Awk
Argument List Too Long When Concatenating Lots of Files in a Folder
Getting Current Working Directory Within Kernel Code
Sync Two Computers Going Through a Bridge with Rsync
How to Set Emacsclient Background as Emacs Background
How Uevents Get Triggered in Kernel
Fatal: Bad Config File Line 1 in /Home/Trx/.Gitconfig
Implement Custom U-Boot Command
Nacl Helper Process Running Without a Sandbox Error Using Chrome Through Selenium in Linux