2012-03-29 22 views
7

मैं रेल पर स्टैक ओवरफ्लो और रूबी के लिए नया हूं। मेरी समस्या यह है कि, जब मैं कमांड डीबी चलाता हूं: डीबी बनाएं या रेक करें: माइग्रेट करें, परीक्षण डेटाबेस प्रभावित है, लेकिन विकास डेटाबेस नहीं है।रेक डीबी: माइग्रेट और रेक डीबी: टेस्ट डेटाबेस पर दोनों काम बनाएं, विकास डेटाबेस

रेल (3.2.2)

मेरी database.yml:

# Warning: The database defined as "test" will be erased and 
# re-generated from your development database when you run "rake". 
# Do not set this db to the same as development or production. 
test: &test 
    adapter: postgresql 
    encoding: unicode 
    database: ticketee_test 
    pool: 5 
    username: ticketee 
    password: my_password_here 

development: 
    adapter: postgresql 
    encoding: unicode 
    database: ticketee_development 
    pool: 5 
    username: ticketee 
    password: my_password_here 

production: 
    adapter: postgresql 
    encoding: unicode 
    database: ticketee_production 
    pool: 5 
    username: ticketee 
    password: my_password_here 

cucumber: 
    <<: *test 

सुझाव के लिए धन्यवाद, लेकिन मुझे डर है कि कारण नहीं है हूँ। मेरा रेलवे_एनवीवी = विकास। जब मैं रेल सर्वर शुरू करता हूं, तो सर्वर विकास डेटाबेस चलाता है। अगर मैं "रेल सर्वर-परीक्षण" चलाता हूं तो सर्वर परीक्षण डेटाबेस का उपयोग करता है। मुझे अभी भी यकीन नहीं है कि मेरे परीक्षण डेटाबेस पर माइग्रेशन क्यों चल रहे हैं ...

अद्यतन: एक सुझाव के आधार पर, मैंने विकास को छोड़कर सभी डेटाबेस कॉन्फ़िगरेशन पर टिप्पणी की, और अब मुझे एक त्रुटि मिली है। मैं postgresql चला रहा हूँ, मेरे पास मणि 'pg' स्थापित है। सबसे पहले, मेरा नया डेटाबेस.एमएल:

development: 
    adapter: postgresql 
    encoding: unicode 
    database: ticketee_development 
    pool: 5 
    username: ticketee 
    password: my_password_here 

# Warning: The database defined as "test" will be erased and 
# re-generated from your development database when you run "rake". 
# Do not set this db to the same as development or production. 
#test: &test 
# adapter: postgresql 
# encoding: unicode 
# database: ticketee_test 
# pool: 5 
# username: ticketee 
# password: my_password_here 

#production: 
# adapter: postgresql 
# encoding: unicode 
# database: ticketee_production 
# pool: 5 
# username: ticketee 
# password: my_password_here 

#cucumber: 
# <<: *test 

मेरा त्रुटि संदेश!

Someguys-MacBook-Air:ticketee someguy$ rake db:migrate 
rake aborted! 
database configuration does not specify adapter 

Tasks: TOP => db:migrate => db:load_config 
(See full trace by running task with --trace) 
Someguys-MacBook-Air:ticketee someguy$ rake db:migrate -t 
** Invoke db:migrate (first_time) 
** Invoke environment (first_time) 
** Execute environment 
** Invoke db:load_config (first_time) 
** Invoke rails_env (first_time) 
** Execute rails_env 
** Execute db:load_config 
rake aborted! 
database configuration does not specify adapter 
/Users/someguy/.rvm/gems/[email protected]/gems/activerecord-3.2.2/lib/active_record/connection_adapters/abstract/connection_specification.rb:45:in `resolve_hash_connection' 
/Users/someguy/.rvm/gems/[email protected]/gems/activerecord-3.2.2/lib/active_record/connection_adapters/abstract/connection_specification.rb:39:in `resolve_string_connection' 
/Users/someguy/.rvm/gems/[email protected]/gems/activerecord-3.2.2/lib/active_record/connection_adapters/abstract/connection_specification.rb:23:in `spec' 
/Users/someguy/.rvm/gems/[email protected]/gems/activerecord-3.2.2/lib/active_record/connection_adapters/abstract/connection_specification.rb:127:in `establish_connection' 
/Users/someguy/.rvm/gems/[email protected]/gems/activerecord-3.2.2/lib/active_record/railtie.rb:76:in `block (2 levels) in <class:Railtie>' 
/Users/someguy/.rvm/gems/[email protected]/gems/activesupport-3.2.2/lib/active_support/lazy_load_hooks.rb:36:in `instance_eval' 
/Users/someguy/.rvm/gems/[email protected]faultGems/gems/activesupport-3.2.2/lib/active_support/lazy_load_hooks.rb:36:in `execute_hook' 
/Users/someguy/.rvm/gems/[email protected]/gems/activesupport-3.2.2/lib/active_support/lazy_load_hooks.rb:43:in `block in run_load_hooks' 
/Users/someguy/.rvm/gems/[email protected]/gems/activesupport-3.2.2/lib/active_support/lazy_load_hooks.rb:42:in `each' 
/Users/someguy/.rvm/gems/[email protected]/gems/activesupport-3.2.2/lib/active_support/lazy_load_hooks.rb:42:in `run_load_hooks' 
/Users/someguy/.rvm/gems/[email protected]/gems/activerecord-3.2.2/lib/active_record/base.rb:718:in `<top (required)>' 
/Users/someguy/.rvm/gems/[email protected]/gems/activerecord-3.2.2/lib/active_record/railties/databases.rake:6:in `block (2 levels) in <top (required)>' 
/Users/someguy/.rvm/gems/[email protected]/gems/rake-0.9.2.2/lib/rake/task.rb:205:in `call' 
/Users/someguy/.rvm/gems/[email protected]/gems/rake-0.9.2.2/lib/rake/task.rb:205:in `block in execute' 
/Users/someguy/.rvm/gems/[email protected]/gems/rake-0.9.2.2/lib/rake/task.rb:200:in `each' 
/Users/someguy/.rvm/gems/[email protected]/gems/rake-0.9.2.2/lib/rake/task.rb:200:in `execute' 
/Users/someguy/.rvm/gems/[email protected]/gems/rake-0.9.2.2/lib/rake/task.rb:158:in `block in invoke_with_call_chain' 
/Users/someguy/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/1.9.1/monitor.rb:211:in `mon_synchronize' 
/Users/someguy/.rvm/gems/[email protected]/gems/rake-0.9.2.2/lib/rake/task.rb:151:in `invoke_with_call_chain' 
/Users/someguy/.rvm/gems/[email protected]/gems/rake-0.9.2.2/lib/rake/task.rb:176:in `block in invoke_prerequisites' 
/Users/someguy/.rvm/gems/[email protected]/gems/rake-0.9.2.2/lib/rake/task.rb:174:in `each' 
/Users/someguy/.rvm/gems/[email protected]/gems/rake-0.9.2.2/lib/rake/task.rb:174:in `invoke_prerequisites' 
/Users/someguy/.rvm/gems/[email protected]/gems/rake-0.9.2.2/lib/rake/task.rb:157:in `block in invoke_with_call_chain' 
/Users/someguy/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/1.9.1/monitor.rb:211:in `mon_synchronize' 
/Users/someguy/.rvm/gems/[email protected]/gems/rake-0.9.2.2/lib/rake/task.rb:151:in `invoke_with_call_chain' 
/Users/someguy/.rvm/gems/[email protected]/gems/rake-0.9.2.2/lib/rake/task.rb:144:in `invoke' 
/Users/someguy/.rvm/gems/[email protected]/gems/rake-0.9.2.2/lib/rake/application.rb:116:in `invoke_task' 
/Users/someguy/.rvm/gems/[email protected]/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `block (2 levels) in top_level' 
/Users/someguy/.rvm/gems/[email protected]/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `each' 
/Users/someguy/.rvm/gems/[email protected]/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `block in top_level' 
/Users/someguy/.rvm/gems/[email protected]/gems/rake-0.9.2.2/lib/rake/application.rb:133:in `standard_exception_handling' 
/Users/someguy/.rvm/gems/[email protected]/gems/rake-0.9.2.2/lib/rake/application.rb:88:in `top_level' 
/Users/someguy/.rvm/gems/[email protected]/gems/rake-0.9.2.2/lib/rake/application.rb:66:in `block in run' 
/Users/someguy/.rvm/gems/[email protected]/gems/rake-0.9.2.2/lib/rake/application.rb:133:in `standard_exception_handling' 
/Users/someguy/.rvm/gems/[email protected]/gems/rake-0.9.2.2/lib/rake/application.rb:63:in `run' 
/Users/someguy/.rvm/gems/[email protected]/gems/rake-0.9.2.2/bin/rake:33:in `<top (required)>' 
/Users/someguy/.rvm/gems/[email protected]/bin/rake:19:in `load' 
/Users/someguy/.rvm/gems/[email protected]/bin/rake:19:in `<main>' 

ऊपर डेटाबेस.आईएमएल का उपयोग करके, रेक डीबी: बनाएं: सभी रैन ने सीधे और मेरी तालिका बनाई। हालांकि, मेरा माइग्रेशन अभी भी ऊपर के रूप में एक ही स्टैक ट्रेस के साथ विफल रहता है।

मैं इस के लिए मेरे database.yml बदल दिया है: विकास: अनुकूलक: sqlite3 डेटाबेस: db/development.sqlite3 पूल: 5 समय समाप्त: 5000

test: 
    adapter: sqlite3 
    database: db/test.sqlite3 
    pool: 5 
    timeout: 5000 

production: 
    adapter: sqlite3 
    database: db/production.sqlite3 
    pool: 5 
    timeout: 5000 

अद्यतन: मेरे डेटाबेस मैं पूरी तरह से बदल यह करने के लिए .yml: ड्रॉप: सब, रेक डाटाबेस के बाद:

development: 
    adapter: sqlite3 
    database: db/development.sqlite3 
    pool: 5 
    timeout: 5000 

test: &test 
    adapter: sqlite3 
    database: db/test.sqlite3 
    pool: 5 
    timeout: 5000 

production: 
    adapter: sqlite3 
    database: db/production.sqlite3 
    pool: 5 
    timeout: 5000 

cucumber: 
    <<: *test 

अब, यह क्या होता है जब मैं रेक db चलाने है चले जाते हैं। रेक डीबी: माइग्रेट कमांड माइग्रेशन चलाता है, एक डीबी/test.sqlite3 बनाता है और इसमें एक टेबल जोड़ता है। तो, मेरा माइग्रेशन अभी भी परीक्षण वातावरण पर चल रहा है। जब मैं रेक वातावरण चलाता हूं RAILS_ENV = विकास डीबी: माइग्रेट करें, वही होता है और मुझे test.sqlite3 फ़ाइल मिलती है ...

+0

मेरी केवल सुझाव आप किसी भी तरह है आपके env में RAILS_ENV = परीक्षण सेट किया है? –

+0

अच्छा सुझाव, मुझे डर है कि यह नहीं है। –

+0

क्या आप सबकुछ पर टिप्पणी करने की कोशिश कर रहे हैं लेकिन विकास और क्या होता है? काम नहीं कर सकता है लेकिन समाधान के लिए आपको एक त्रुटि दे सकता है। – huntsfromshadow

उत्तर

2

मैं कल रात से शुरू होने में ठीक उसी समस्या थी। कोई विचार नहीं कि इसके कारण क्या हो सकता है, लेकिन आखिर में एक समाधान मिला जो काम करता था। config/वातावरण/develop.rb में कॉन्फ़िगर ब्लॉक के अंदर, मैं कहा:

Rails.env = 'development' 

मुझे आशा है कि आप के लिए भी

+1

कॉन्फ़िगरेशन/वातावरण/name.rb डेटाबेस.yml में नाम से मेल खाना चाहिए। रेल विन्यास की तुलना में अधिक सम्मेलन है। – Sairam

0

आप अपनी yml फ़ाइल में host: localhost खो रहे हैं।

यह करने के लिए आपके विन्यास परिवर्तित करें:

development: 
    adapter: postgresql 
    encoding: unicode 
    host: localhost 
    database: ticketee_development 
    pool: 5 
    username: ticketee 
    password: my_password_here 
+0

मैंने मेजबान, एक ही समस्या निर्दिष्ट की। याद रखें, मैं उपरोक्त परीक्षण डेटाबेस में माइग्रेशन लिख सकता हूं लेकिन मैं किसी भी परिस्थिति में विकास के लिए नहीं लिख सकता। –

+0

मुझे तब एक सफेद अंतरिक्ष मुद्दे पर संदेह है। सभी अदृश्य पात्रों को देखने के लिए 'vi/path/to/database.yml' प्रकार': सेट सूची 'के साथ vim में फ़ाइल खोलें। – Josh

+0

मैंने अभी कोशिश की है, मैं $ प्रतीकों को सही देखता हूं जहां मैं उन्हें वीआई टिप के लिए धन्यवाद देखने की उम्मीद करता हूं, जो काम में आ जाएगा। –

0

काम करता है त्रुटि forking! शायद कुछ कैशिंग या लॉग समस्याएं यह दर्शाती है कि हमारे कोड में त्रुटियों में से कुछ भी नहीं।

मेरी टीम इसे हल करती है।

  • प्रोजेक्ट को हटाने

  • Git database.yml विन्यास

  • शुरू सर्वर

सब कुछ ठीक है परियोजना

  • क्लोन!

    एक ही परियोजना त्रुटियों चले गए! तो हमें लगता है कि यह env समस्याएं या कैच या लॉग है।

  • 3

    ActiveRecord/lib/active_record/कार्य/database_tasks.rb में एक 'शानदार' लाइन है:

    environments << 'test' if environment == 'development' && ENV['RAILS_ENV'].nil? 
    

    जो, 8 जनवरी तक, 2014 की तरह देखा:

    environments << 'test' if environment == 'development' 
    
    2

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

    rake db:reset 
    

    या

    rake db:drop db:create 
    

    अपने परिवेश के आधार पर, आप माइग्रेशन करने के लिए सक्षम होना चाहिए।

    rake db:migrate 
    

    पुनश्च - आप प्रत्येक आदेश की शुरुआत में bundle exec जोड़ने के लिए हो सकता है।

    शुभकामनाएं।

    0

    आप रेक डाटाबेस का उपयोग कर सकते हैं: विस्थापित RAILS_ENV = "विकास"

    या आप की तरह

    सेट RAILS_ENV = विकास का उपयोग कर सकते

    रेक db: विस्थापित

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