मैं डीबी को रेक करने की कोशिश कर रहा हूं: माइग्रेशन मेरे हेर्कू इंस्टेंस में और मुझे एक त्रुटि मिलती है। एफएक्यू ने मेरी त्रुटि को नीचे वर्णित किया:मैं हेरोोकू में कॉलम प्रकार कैसे बदलूं?
Cannot change column type
Example: PGError: ERROR: column “verified_at” cannot be cast to type “date”
Cause: PostgreSQL doesn’t know how to cast all the rows in that table to the specified type. Most likely it means you have an integer or a string in that column.
Solution: Inspect your records and make sure they can be converted to the new type. Sometimes it’s easier to just avoid using change_column, renaming/creating a new column instead.
अब मैं इस माइग्रेशन को कैसे बदलूं। यह समस्या है जो मेरे पास है।
t.string :date_entered
एक बाद माइग्रेशन में, मैं निम्नलिखित है:
change_column :contacts, :date_entered, :date
यह change_column समस्या प्रतीत होता है जो मेरे संपर्क तालिका के लिए, मैं निम्नलिखित बनाया।
क्या मुझे ... माइग्रेशन के हाथ से बदलना चाहिए? क्या कोई तरीका है कि मैं अपने टेबल में डेटा साफ़ कर सकता हूं (मुझे नहीं पता था कि हेरोोकू टेबल में डेटा को पहचान लेगा क्योंकि मैं रेक कर रहा हूं)।
मुझे स्पष्ट रूप से इस मूल्य को बदलने की आवश्यकता है और यह मेरे पूरे एप्लिकेशन में उपयोग किया जाता है। धन्यवाद।
यही वह है जो मैं कोशिश कर रहा हूं ... विचार?
def self.up
#change_column :contacts, :date_entered, :date
#this fails in postgres, so trying the same outcome
rename_column :contacts, :date_entered, :date_entered_old
add_column :contacts, :date_entered, :date
remove_column :contacts, :date_entered_old
end
def self.down
add_column :contacts, :date_entered_old
remove_column :contacts, :date_entered
rename_column :contacts, :date_entered_old, :date_entered
end
#reset_column_information के लिए +1, जो मैंने पहले कभी नहीं देखा था का एक संशोधित और परीक्षण संस्करण है। ऐसा लगता है कि यह आवश्यक होने पर उन दुर्लभ समयों में आसान होगा। – jdl
ditto re: रीसेट करें। – Angela
अभी भी दो साल बाद काम करता है! –