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.

--
Posted via http://www.ruby-forum.com/.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

Search Discussions

  • Colin Law at Feb 17, 2012 at 4:24 pm

    On 17 February 2012 14:31, Felipe Pieretti Umpierre wrote:
    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 ?
    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
    Thank you.

    --
    Posted via http://www.ruby-forum.com/.

    --
    You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.


    --
    gplus.to/clanlaw

    --
    You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
  • Felipe Pieretti Umpierre at Feb 17, 2012 at 4:36 pm
    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.

    --
    Posted via http://www.ruby-forum.com/.

    --
    You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
  • Colin Law at Feb 17, 2012 at 4:40 pm

    On 17 February 2012 16:36, Felipe Pieretti Umpierre 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
    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.

    --
    Posted via http://www.ruby-forum.com/.

    --
    You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.


    --
    gplus.to/clanlaw

    --
    You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
  • Felipe Pieretti Umpierre at Feb 17, 2012 at 4:44 pm
    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 >

    --
    Posted via http://www.ruby-forum.com/.

    --
    You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
  • Colin Law at Feb 17, 2012 at 4:48 pm

    On 17 February 2012 16:44, Felipe Pieretti Umpierre 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

    --
    You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
  • Felipe Pieretti Umpierre at Feb 17, 2012 at 4:51 pm
    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

    --
    Posted via http://www.ruby-forum.com/.

    --
    You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
  • Colin Law at Feb 17, 2012 at 4:56 pm

    On 17 February 2012 16:51, Felipe Pieretti Umpierre 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

    --
    You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
  • Felipe Pieretti Umpierre at Feb 17, 2012 at 5:06 pm
    Man, I don't understand, but I reset my server, and refresh my page and
    go OK.

    Thank you for your time.

    --
    Posted via http://www.ruby-forum.com/.

    --
    You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
  • Colin Law at Feb 17, 2012 at 5:15 pm

    On 17 February 2012 17:05, Felipe Pieretti Umpierre 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

    --
    You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouprubyonrails-talk @
categoriesrubyonrails
postedFeb 17, '12 at 2:31p
activeFeb 17, '12 at 5:15p
posts10
users2
websiterubyonrails.org
irc#RubyOnRails

People

Translate

site design / logo © 2021 Grokbase