Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PG::Error: ERROR: relation "users" does not exist

sorry for disturb you but i have a lot of question about this error. first this is my user_controller rspec file

require 'spec/spec_helper'

describe UserController do

it "create new user" do
    post "create"
    assigns[:users].should_not be_new_record
end
end

this is my UserController

 class UserController < ApplicationController
   def create
     @users = User.new
     if @users.save
       flash[:notice] = 'new user was successfully created.'
     else
       render :action => :new
     end
   end

   def new
     @user = User.new
   end
 end

and my routes.rb (i think the problem is here, excuse me but i`m new in this language)

Estaciones::Application.routes.draw do
  devise_for :users

  root :to => "home#index"
  resources :user
end

when i try to test my user_controller_rspec then i get this error

Failures:

1) UserController create new user
   Failure/Error: post "create"
   ActiveRecord::StatementInvalid:
     PG::Error: ERROR:  relation "users" does not exist
     LINE 4:              WHERE a.attrelid = '"users"'::regclass
                                             ^
     :             SELECT a.attname, format_type(a.atttypid, a.atttypmod), d.adsrc, a.attnotnull
                   FROM pg_attribute a LEFT JOIN pg_attrdef d
                     ON a.attrelid = d.adrelid AND a.attnum = d.adnum
                    WHERE a.attrelid = '"users"'::regclass
                    AND a.attnum > 0 AND NOT a.attisdropped
                  ORDER BY a.attnum
 # ./app/controllers/user_controller.rb:3:in `new'
 # ./app/controllers/user_controller.rb:3:in `create'
 # ./spec/controllers/user_controller_spec.rb:6

 Finished in 0.01722 seconds
 1 example, 1 failure

 Failed examples:

 rspec ./spec/controllers/user_controller_spec.rb:5 # UserController create new user

how i can fix it... thanks

like image 500
Asantoya Avatar asked Jul 17 '12 19:07

Asantoya


People also ask

How do I connect to a Postgres database?

In order to connect to a database you need to know the name of your target database, the host name and port number of the server, and what user name you want to connect as. psql can be told about those parameters via command line options, namely -d, -h, -p, and -U respectively.

What is a Postgres relation?

PostgreSQL is a relational database management system ( RDBMS ). That means it is a system for managing data stored in relations. Relation is essentially a mathematical term for table.

Is Postgres case sensitive?

PostgreSQL names are case sensitive. By default, AWS Schema Conversion Tool (AWS SCT) uses object name in lowercase for PostgreSQL. In most cases, you'll want to use AWS Database Migration Service transformations to change schema, table, and column names to lower case.

How do I list databases in PostgreSQL?

Step 1: Log in to the server using the SQL Shell (psql) app. Step 2: Run the following query: SELECT datname FROM pg_database; psql runs the query against the server and displays a list of existing databases in the output.


2 Answers

run this

 rake db:migrate

then this

 rake db:test:prepare
like image 136
drhenner Avatar answered Nov 05 '22 15:11

drhenner


Alternative variant

RAILS_ENV=test rake db:migrate

like image 20
Sergiy Seletskyy Avatar answered Nov 05 '22 17:11

Sergiy Seletskyy