16

मैं भागने की कोशिश की:रूबी 3 पर रूबी में एक बार में सभी माइग्रेशन को वापस कैसे करें?

rake db:migrate VERSION=0 

यह पिछले एक को छोड़कर सभी माइग्रेशन reverts।

तब मैं भागने की कोशिश की:

rake db:migrate:down VERSION=<timestamp_of_last_migration> 

लेकिन यह या तो वापस लौटने नहीं दिया। क्यूं कर ?

क्या कोई ऐसा आदेश है जो सभी down विधियों को एक बार में चलाता है?

+1

से लिया कैसे सभी माइग्रेशन रोलबैक करने पर सर्च कर रहे हैं लौट जाएगा, मैं इस सवाल पर ठोकर खाई। मैं बस कहना चाहता हूं कि आजकल (रेल 3.2.9) 'रेक डीबी: माइग्रेट VERSION = 0' ठीक काम कर रहा है, सभी माइग्रेशन को वापस कर रहा है। – janosrusiczki

+0

यह प्रश्न गलत या पुराना प्रतीत होता है। 'रेक डीबी: माइग्रेट VERSION = 0' प्रत्येक माइग्रेशन रोलबैक, ** पहले एक सहित ** **। –

उत्तर

11

यदि आपका डेटाबेस केवल इस प्रोजेक्ट से संबंधित है, और आप अपने माइग्रेशन में सब कुछ पूर्ववत करने का प्रयास कर रहे हैं, तो मैं बस डेटाबेस छोड़ दूंगा, और फिर रेक डीबी चलाएं: बनाएं।

फिर आपके पास जाने के लिए एक खाली डेटाबेस तैयार है।

या क्या कोई और कारण है कि आप नीचे की स्क्रिप्ट चलाने की कोशिश कर रहे हैं?

+0

यही वह है जो मैंने अंततः किया था। लेकिन, मुझे अभी भी आश्चर्य है कि ऊपर दिए गए आदेश क्यों काम नहीं करते ... –

+2

रेल रेक रेक कार्यों के माध्यम से टोल किया गया, और यह रेक डीबी जैसा दिखता है: ड्रॉप डीबी: बनाना ही एकमात्र असली विकल्प है। मैं कहूंगा कि माइग्रेशन आपको कुछ भी वापस जाने नहीं देगा, क्योंकि वे माइग्रेशन के अंदर घूमने के लिए थे। शून्य पर वापस रीसेट नहीं कर रहा है। – boymc

10

आप इस सूची को देख सकते हैं। अनिवार्य रूप से सब कुछ को मिटाने

rake db:migrate:down VERSION=<timestamp_of_first_migration> 

यह आपका पहला माइग्रेशन के लिए self.down चलेगा,:

हो सकता है कि यह मदद कर सकता है आप

rake db:create[:all]: If :all not specified then create the database defined in config/database.yml for the current RAILS_ENV. If :all is specified then create all of the databases defined in config/database.yml. 
rake db:fixtures:load: Load fixtures into the current environment's database. Load specific fixtures using FIXTURES=x,y 
rake db:migrate [VERSION=n]: Migrate the database through scripts in db/migrate. Target specific version with VERSION=n 
rake db:migrate:redo [STEP=n]: (2.0.2) Revert the database by rolling back "STEP" number of VERSIONS and re-applying migrations. 
rake db:migrate:reset: (2.0.2) Drop the database, create it and then re-apply all migrations. The considerations outlined in the note to rake db:create apply. 
rake db:reset: Drop and re-create database using db/schema.rb. The considerations outlined in the note to rake db:create apply. 
rake db:rollback [STEP=N]: (2.0.2) Revert migration 1 or n STEPs back. 
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:sessions:clear: Clear the sessions table 
rake db:sessions:create: Creates a sessions table for use with CGI::Session::ActiveRecordStore 
rake db:structure:dump: Dump the database structure to a SQL file 
rake db:test:clone: Recreate the test database from the current environment's database schema 
rake db:test:clone_structure: Recreate the test databases from the development structure 
rake db:test:prepare: Prepare the test database and load the schema 
rake db:test:purge: Empty the test database 
2

कोशिश। कम से कम, यह सिर्फ मेरे लिए किया था!

संबंधित मुद्दे