Rails Heroku更改列数据类型



我运行这个命令是为了将数据库部署到heroku

heroku run rails db:migrate

但是我得到了这个错误

rails aborted!
StandardError: An error has occurred, this and all later migrations canceled:
PG::UndefinedObject: ERROR:  type "dateti" does not exist
LINE 1: ALTER TABLE "users" ADD "activated_at" dateti
^

之后我更改了错误的数据类型"日期";datetime"

class AddActivationToUsers < ActiveRecord::Migration[7.0]
def change
add_column :users, :activation_digest, :string
add_column :users, :activated, :boolean, default: false
add_column :users, :activated_at, :datetime
end
end

但一切都没有改变。仍然得到这个错误。对于开发和测试,我使用sqlite3,对于生产,我使用postgresql。只有当我尝试部署到heroku时才会出现此错误。在本地数据库上一切正常

数据库。yml文件

# SQLite. Versions 3.8.0 and up are supported.
#   gem install sqlite3
#
#   Ensure the SQLite 3 gem is defined in your Gemfile
#   gem "sqlite3"
#
default: &default
adapter: sqlite3
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
timeout: 5000
development:
<<: *default
database: db/development.sqlite3
# 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:
<<: *default
database: db/test.sqlite3
production:
adapter: postgresql
encoding: unicode
# For details on connection pooling, see Rails configuration guide
# https://guides.rubyonrails.org/configuring.html#database-pooling
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
database: sample_app_production
username: sample_app
password: <%= ENV['SAMPLE_APP_DATABASE_PASSWORD'] %>

AddActivationToUsers文件中更改activited_at (datetime)之前。你必须回滚AddActivationToUsers在db.

  1. rails db:rollback STEP=n (n迁移,其中n是要回滚的最近迁移的数量)
  2. 更改activited_at :datetime并保存
  3. db: rails迁移