Not find my Table

Hello, I call my Model in my Controller:

class ProjectsController < ApplicationController
def index
@projects = Project.all
end
end

my model:

class Project < ActiveRecord::Base
has_many :items
end

my migration:

class CreateProjects < ActiveRecord::Migration
def change
create_table :projects do |t|
t.references :users
t.string “title”
t.text “description”
t.timestamps
end

add_index :projects, "users_id"

end

def down
remove_index :projects, “users_id”
drop_table :projects
end
end

The error:

ActiveRecord::StatementInvalid in ProjectsController#index

Could not find table ‘projects’

MySQL:

mysql> SHOW TABLES;
±------------------------------+
| Tables_in_younner_development |
±------------------------------+
| categories |
| items |
| items_projects |
| projects |
| schema_migrations |
| users |
±------------------------------+
6 rows in set (0.00 sec)

mysql> SHOW FIELDS FROM projects;
±------------±-------------±-----±----±--------±---------------+
| Field | Type | Null | Key | Default | Extra |
±------------±-------------±-----±----±--------±---------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| users_id | int(11) | YES | MUL | NULL | |
| title | varchar(255) | YES | | NULL | |
| description | text | YES | | NULL | |
| created_at | datetime | NO | | NULL | |
| updated_at | datetime | NO | | NULL | |
±------------±-------------±-----±----±--------±---------------+
6 rows in set (0.00 sec)

My question is.

Why my application don’t find my table ?

Thank you.

Hello Colin, thank you for you answer.

I made a rake db:migrate VERSION=0 and again a rake db:migrate.

So I put what you say to me do:

1.9.3-p0 :002 > Product.first
NameError: uninitialized constant Product
from (irb):2
from
/home/felipe/.rvm/gems/ruby-1.9.3-p0/gems/railties-3.2.1/lib/rails/commands/console.rb:47:in
start' from /home/felipe/.rvm/gems/ruby-1.9.3-p0/gems/railties-3.2.1/lib/rails/commands/console.rb:8:instart’
from
/home/felipe/.rvm/gems/ruby-1.9.3-p0/gems/railties-3.2.1/lib/rails/commands.rb:41:in
<top (required)>' from script/rails:6:inrequire’
from script/rails:6:in `’

My database.yml

development:
adapter: mysql2
encoding: utf8
database: younner_development
user: younner
password:
pool: 5
timeout: 5000

I don’t understand…

Thank you again.

On 17 February 2012 16:36, Felipe Pieretti U.
[email protected] wrote:

Hello Colin, thank you for you answer.

I made a rake db:migrate VERSION=0 and again a rake db:migrate.

So I put what you say to me do:

1.9.3-p0 :002 > Product.first

That should be Project.first

Colin

`<top (required)>’
password:

You received this message because you are subscribed to the Google G. “Ruby
on Rails: Talk” group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.


gplus.to/clanlaw

Huge mistake!!!

1.9.3-p0 :004 > Project.first
Project Load (0.4ms) SELECT projects.* FROM projects LIMIT 1
=> nil
1.9.3-p0 :005 >

On 17 February 2012 16:44, Felipe Pieretti U.
[email protected] wrote:

Huge mistake!!!

1.9.3-p0 :004 > Project.first
Project Load (0.4ms) SELECT projects.* FROM projects LIMIT 1
=> nil

That is ok then, the table is there but empty. Now what are you
getting from the app? Show us the full error.

By the way it is easier to follow the thread (particularly for those
who find the thread later) if you insert your reply into the previous
post rather than posting at the top.

Colin

On 17 February 2012 14:31, Felipe Pieretti U.
[email protected] wrote:

t.string “title”
end
mysql> SHOW TABLES;
6 rows in set (0.00 sec)
| updated_at | datetime | NO | | NULL | |
±------------±-------------±-----±----±--------±---------------+
6 rows in set (0.00 sec)

My question is.

Why my application don’t find my table ?

Are you sure you are connected to the correct database?
Are you running in development or production mode?
What happens if you do
rails console
Project.first

Do the other models work?

Colin

For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.


gplus.to/clanlaw

ActiveRecord::StatementInvalid in ProjectsController#index

Could not find table ‘projects’

Rails.root: /home/felipe/rails/Younner
Application Trace | Framework Trace | Full Trace

app/controllers/projects_controller.rb:3:in `index’

Request

Parameters:

None

Show session dump

Show env dump
Response

Headers:

None

Man, I don’t understand, but I reset my server, and refresh my page and
go OK.

Thank you for your time.

On 17 February 2012 16:51, Felipe Pieretti U.
[email protected] wrote:

ActiveRecord::StatementInvalid in ProjectsController#index

Could not find table ‘projects’

Can you post the terminal output when you start the server and then go
to that page (right from the command that starts the server).

By the way it is easier to follow the thread (particularly for those
who find the thread later) if you insert your reply into the previous
post rather than posting at the top.

Colin

On 17 February 2012 17:05, Felipe Pieretti U.
[email protected] wrote:

Man, I don’t understand, but I reset my server, and refresh my page and
go OK.

Are you sure the server was running in development mode previously,
and not production?

On a separate issue, if you want project belongs_to user then you
should have said t.references :user (not :users) and the column should
be user_id not users_id.

I don’t know whether I mentioned it previously but it is easier to
follow the thread (particularly for those who find the thread later)
if you insert your reply into the previous post rather than posting at
the top.

Thank you for your time.

No problem.

Colin