# Issue with scaffolding with rail 2.2 and mySQL

**URL:** <https://www.ruby-forum.com/t/issue-with-scaffolding-with-rail-2-2-and-mysql/155561>\
**Category:** Rails\
**Created:** [December 13, 2008, 2:18pm UTC](https://www.ruby-forum.com/t/issue-with-scaffolding-with-rail-2-2-and-mysql/155561 "2008-12-13T14:18:18Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![mikari](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/53a042/32.png) [@mikari](https://www.ruby-forum.com/u/mikari)\
**Post date:** [December 13, 2008, 2:18pm UTC](https://www.ruby-forum.com/t/issue-with-scaffolding-with-rail-2-2-and-mysql/155561/1 "2008-12-13T14:18:18Z")

</div>

Hi guys,  
I’m having problems when creating basic web applications using rails  
2.2 and mySQL databases.  
If I create the following table in a database named  
moviecritc\_development:

CREATE TABLE movies (  
id INT NOT NULL AUTO\_INCREMENT PRIMARY\_KEY,  
name VARCHAR(30) NOT NULL );

and then run the following ruby commands:

rails -d mysql moviecritic (creates all the necessary files without any  
issue.)

I then modify the config/database.yml to include the root password to  
my database and run then ruby the following ruby command:

ruby script/generate scaffold Movie (creates usual files without error).

If i now view the db/migrate.create\_movies.rb i see the following:  
class CreateMovies \< ActiveRecord::Migration  
def self.up  
create\_table :movies do |t|

```
  t.timestamps
end

```

end

def self.down  
drop\_table :movies  
end  
end

It doesn’t make a reference to the name column i created! This is  
reflected when i navigate to localhost:3000/movies/new i only see a  
Back link and a Create Button, i don’t see a NAME FIELD INPUT.

Has anyone any ideas why this is happening?  
Thanks in advance,  
Stephen

---

<div class="post-metadata">

**Author:** ![mikari](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/53a042/32.png) [@mikari](https://www.ruby-forum.com/u/mikari)\
**Post date:** [December 13, 2008, 2:22pm UTC](https://www.ruby-forum.com/t/issue-with-scaffolding-with-rail-2-2-and-mysql/155561/2 "2008-12-13T14:22:59Z")

</div>

On Dec 13, 11:11 am, “Stephen Morrison” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> ```
> create_table :movies do |t|
> 
> ```
> 
> It doesn’t make a reference to the name column i created! This is  
> You’ve got things back to front. the migration generator does not look  
> at an existing table. It’s expecting that it will be creating a new  
> table.  
> The scaffolding stuff used to introspect the database but that died a  
> while back

These days what you should do is

- create your rails app
- create the database

ruby script/generate scaffold Movie name:string  
This will create the migration, views and controller. The migration  
will create a table with a name column called string and the views  
will show that field.  
then run  
rake db:migrate

to run the migration (ie actually create the table).

Fred

---

<div class="post-metadata">

**Author:** ![mikari](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/53a042/32.png) [@mikari](https://www.ruby-forum.com/u/mikari)\
**Post date:** [January 9, 2009, 2:36am UTC](https://www.ruby-forum.com/t/issue-with-scaffolding-with-rail-2-2-and-mysql/155561/3 "2009-01-09T02:36:31Z")

</div>

I think that’s crap. The scaffold should create the table if it does  
not exist but if the table already exists then inspect the table and  
generate the appropriate stuff. What a pain in the ass.

On Dec 13 2008, 7:22 am, Frederick C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![mikari](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/53a042/32.png) [@mikari](https://www.ruby-forum.com/u/mikari)\
**Post date:** [January 7, 2009, 10:05pm UTC](https://www.ruby-forum.com/t/issue-with-scaffolding-with-rail-2-2-and-mysql/155561/4 "2009-01-07T22:05:13Z")

</div>

Thanks for the help! Much appreciated!
