Topic: Unable to generate scaffold

I have InstantRails installed and am trying to create a very basic application.  It uses a database called hierarchy_development that is created and then has the following very simple SQL code to create the tables -- I just have two:

DROP TABLE IF EXISTS song;
DROP TABLE IF EXISTS composer;

create table composer(
    name char(50) not null default '',
    id int not null auto_increment,
    primary key(id)
) engine=InnoDB;

create table song(
    name char(50) not null default '',
    id int not null auto_increment,
    composer_id int not null,
    constraint fk_song_composer foreign key (composer_id) references composer(id),
    primary key(id)
) engine=InnoDB;

The database.yml for the application file reads as follows:

development:
  adapter: mysql
  database: hierarchy_development
  username: root
  password:
  host: localhost

test:
  adapter: mysql
  database: hierarchy_test
  username: root
  password:
  host: localhost

production:
  adapter: mysql
  database: hierarchy_production
  username: root
  password:
  host: localhost

When I attempt to use the statement "ruby script\generate scaffold song song" from my application directory it generates a few files and then gives me the following error:

      exists  app/controllers/
      exists  app/helpers/
      exists  app/views/song
      exists  app/views/layouts/
      exists  test/functional/
  dependency  model
      exists    app/models/
      exists    test/unit/
      exists    test/fixtures/
   identical    app/models/song.rb
   identical    test/unit/song_test.rb
   identical    test/fixtures/songs.yml
       error  Before updating scaffolding from new DB schema, try creating a table for your model (Song)

This is pretty common; I've ready some threads about the error but none of the given solutions have worked for me.

As a side note, I tried to run the statement "ruby script\generate scaffold recipies recipies" in the application directory for the sample cookbook application and got the same error.

Thanks for your help.

Re: Unable to generate scaffold

Any reason your not using migrations for creating the tables?

Re: Unable to generate scaffold

I'm creating the DB from scratch

Re: Unable to generate scaffold

brahmsfan21 wrote:

I'm creating the DB from scratch

You could just as easily do that by using migrations. Delete your application and create a new one. Make sure your database is empty aswell. Then generate the models and controllers for your classes Composer and Song (this will automatically create the needed migrations). Here you can see how to use them in order to achieve the same result as your SQL statement and at the same time even adding som valuable features for the future.

After generating the necessary models and controllers and prompting:

rake db:migrate

You should be able to scaffold.