开发者

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 t开发者_Python百科o run rake db:migrate but it didn't create a new table. Thanks.


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.


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.


If you DROP a MySQL table, you cannot recover that data unless you've made a backup.


This is 2 step process:

  1. Create the table only with table_name.
  2. Run the below command:
rake db:migrate:redo VERSION=20220609102335
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜