My migrations are causing SQL problems

I am running: rake db:migrate, and I am getting this error. I am some
what of a beginner, and I can't seem to understand migrations, because
I can't fix this problem :frowning:

== 2 CreateWorks: migrating

Somehow the table 'works' has already been created in that database.
Log into mysql from the command line or however else you interact
directly with the database and drop that table manually (drop table
works;). Then you can recreate it using your migration.

Won't that cause all my data to be lost though?

So do you suggest maybe me exporting my whole database, then inserting
it after doing a db:migrate?

If you already have the table works in your database, why did you
create a migration file to recreate it? I had assumed that you had a
table 'works' as a side affect of an error in a migration. If you
already have 'works' and you want what you have, then don't have a
migration that creates the table. Was the migration created when you
ran 'script/generate scaffold'? If so, you want the code that was
created but NOT the migration. For now, just delete the migration
file. In future, I am pretty sure there is a flag you can pass to
script/generate to tell it not to create the migration file.

Are migrations really that important? My migrations obviously are
really messed up, yet my application works fine! Will it effect me
when I try to deploy my app, will the effect me then?


Migrations are an easy way to recreate a database that works with your
application. If you have another way to create a valid database (for
example migrating the data using mysqldump), then migrations are not

However, I would, if I were you, spend some time getting your
migrations straightened out. One way to do that without disrupting
your working development database is to run them forwards and
backwards in a disposable database (for example your test database)
until they run without error and reproduce the structure you currently
have. Hint: "rake db:schema:dump" on your development database and
then on the play database. When the two schema.rb files match, your
migrations will reproduce the structure of your dev database.

I would like to echo Cynthia's comments. Migrations are important
because they make your life a lot easier when it comes to creating and
updating your tables.

If you've got an existing database, look at the following page:

Definitely take the time to pick up migrations. It's simple once you
get the hang of it. It will also make your application portable...
meaning that if you decide to switch databases, you won't have to
recreate your database. ActiveRecord will do that for you.

That forum topic fixed it! Thanks a bunch!

No problemo!