13

क्या मौजूदा एप्लिकेशन से डेटाबेस और सभी माइग्रेशन रिकॉर्ड्स इत्यादि को पूरी तरह से हटा देना संभव है ताकि मैं डेटाबेस को स्क्रैच से फिर से डिजाइन कर सकूं?रेल में डेटाबेस को नष्ट/निकालें

उत्तर

39

rake -T जारी करके आप निम्नलिखित डेटाबेस कार्यों:

rake db:create   # Create the database from DATABASE_URL or config/database.yml for the current Rails.env (use db:create:all to create all dbs in the config) 
rake db:drop   # Drops the database using DATABASE_URL or the current Rails.env (use db:drop:all to drop all databases) 
rake db:fixtures:load # Load fixtures into the current environment's database 
rake db:migrate   # Migrate the database (options: VERSION=x, VERBOSE=false) 
rake db:migrate:status # Display status of migrations 
rake db:rollback  # Rolls the schema back to the previous version (specify steps w/ STEP=n) 
rake db:schema:dump  # Create a db/schema.rb file that can be portably used against any DB supported by AR 
rake db:schema:load  # Load a schema.rb file into the database 
rake db:seed   # Load the seed data from db/seeds.rb 
rake db:setup   # Create the database, load the schema, and initialize with the seed data (use db:reset to also drop the db first) 
rake db:structure:dump # Dump the database structure to db/structure.sql 
rake db:version   # Retrieves the current schema version number 

तो bundle exec rake db:drop:all जारी करने के लिए और यदि आप सभी माइग्रेशन को हटाना चाहते हैं, और एक ssuming आप केवल माइग्रेशन को हटाना चाहते हैं, उन्हें हटाएं और नए लिखें।

यदि आप अपने मॉडल भी बदलना चाहते हैं, तो rails d model का उपयोग करें।

4

इस डाटाबेस से छुटकारा मिल जाएगा:

rake db:drop 

और प्रत्येक माइग्रेशन के लिए आप हैं, वे:

rails d migration migration_name 
+0

ग्रेट धन्यवाद। क्या मुझे कुछ और साफ करना चाहिए? (मैंने बस रेल सीखना शुरू किया)। – fearofawhackplanet

0

हां, डेटाबेस और माइग्रेशन को हटाने के लिए यह संभव है।

rake db:drop 
rake db:rollback 
rails d migration 'migration name' 
rake db:create 
rake db:migrate 
rake db:seed 
rake db:test:prepare 
संबंधित मुद्दे