Sto cercando di rastrellare il db: migrazioni nella mia istanza di heorku e ottengo un errore. Le FAQ descrivevano il mio errore come riportato di seguito:Come cambio il tipo di colonna in Heroku?
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.
Come modificare questa migrazione ora. Questo è il problema che ho. Per la mia tabella Contatti, ho creato il seguente:
t.string :date_entered
In una migrazione tardi, faccio la seguente:
change_column :contacts, :date_entered, :date
Questo change_column sembra essere il problema.
Devo ... modificare manualmente la migrazione? C'è un modo per pulire i dati nei miei tavoli (non sapevo che Heroku avrebbe riconosciuto i dati nella tabella perché sto facendo un rake).
Ovviamente ho bisogno di cambiare questo valore e viene utilizzato in tutta la mia applicazione. Grazie.
Questo è quello che sto provando ... pensieri?
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
+1 per #reset_column_information, che non avevo mai visto prima. Sembra che sarebbe utile in quei tempi molto rari in cui è necessario. – jdl
idem re: reset. – Angela
Ancora funziona oltre due anni dopo! –