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:

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:

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

> 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 ?

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

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:in
`start'
  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:in `require'
  from script/rails:6:in `<main>'

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.

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

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 >

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

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

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

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

Thank you for your time.

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