Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails - Accidentally dropped my table

Being stupid, and careless, I accidentally dropped my table with contents. How do I re-create that table again in RAils? Tried to run rake db:migrate but it didn't create a new table. Thanks.

like image 489
Victor Avatar asked Nov 24 '10 16:11

Victor


People also ask

Can a dropped table be recovered?

For a dropped table to be recoverable, the table space in which the table resides must have the DROPPED TABLE RECOVERY option turned on. This option can be enabled during table space creation, or by invoking the ALTER TABLESPACE statement.


2 Answers

You can run specific migrations regardless of whether or not they have been run.

rake db:migrate:up VERSION=20101124121304

This runs the up method on the migration created on 11/24/2010 at 12:13:04 PM. Find the migration file that contains the table you need and rerun the migration. That being said, any data from that table is not recoverable.

like image 150
Mike Yockey Avatar answered Oct 07 '22 13:10

Mike Yockey


You can't recover data, but I'm assuming you just want structure?

Check if you db/schema.rb is up-to-date. It should contain a current structure definition of your table.

You can recreate your entire database from db/schema.rb using rake db:setup. I'm not aware of a method that recreates just a single table.

But perhaps you can create a new database using a different name, and copy the structure. Or tediously recreate the table yourself based on what's in db/schema.rb.

like image 20
Stéphan Kochen Avatar answered Oct 07 '22 12:10

Stéphan Kochen