Rails Migrations are pending

tablecell · 2021年10月31日 · 最后由 Rei 回复于 2021年10月31日 · 598 次阅读

status 500 error "Internal Server Error" exception "#<ActiveRecord::PendingMigrationError:

Migrations are pending. To resolve this issue, run:

bin/rails db:migrate RAILS_ENV=development

"

执行 bin/rails db:migrate RAILS_ENV=development 提示 SQLite3::SQLException: table "xxtable" already exists:

xxtable 表已经存在

把数据库删了重新跑吧。。。

pynix 回复

就是用的这个办法解决了 命令行给的提示是误导

如果发现一个 Migrations 写错了,或者字段不对,能直接把 Migrations 文件 删除吗?

tablecell 回复

不能。一般是增加一个新的 migration。

chenge 回复

这个 migration 就是区块链啊

tablecell 回复

主要是支持 undo,不过我从来没有用过 undo,有点复杂不好理解。

$ bin/rails -T | grep db
rails db:create                          # Creates the database from DATABASE_URL or config/database.yml for the current RAILS_ENV (use db:create:all to create all databases in the config). Without RAILS_ENV or when RAILS_ENV is development, it defaults to creating the development and test databases, except when DATABASE_URL is present
rails db:drop                            # Drops the database from DATABASE_URL or config/database.yml for the current RAILS_ENV (use db:drop:all to drop all databases in the config). Without RAILS_ENV or when RAILS_ENV is development, it defaults to dropping the development and test databases, except when DATABASE_URL is present
rails db:environment:set                 # Set the environment value for the database
rails db:fixtures:load                   # Loads fixtures into the current environment's database
rails db:migrate                         # Migrate the database (options: VERSION=x, VERBOSE=false, SCOPE=blog)
rails db:migrate:down                    # Runs the "down" for a given migration VERSION
rails db:migrate:redo                    # Rolls back the database one migration and re-migrates up (options: STEP=x, VERSION=x)
rails db:migrate:status                  # Display status of migrations
rails db:migrate:up                      # Runs the "up" for a given migration VERSION
rails db:prepare                         # Runs setup if database does not exist, or runs migrations if it does
rails db:reset                           # Drops and recreates the database from db/schema.rb for the current environment and loads the seeds
rails db:rollback                        # Rolls the schema back to the previous version (specify steps w/ STEP=n)
rails db:schema:cache:clear              # Clears a db/schema_cache.yml file
rails db:schema:cache:dump               # Creates a db/schema_cache.yml file
rails db:schema:dump                     # Creates a database schema file (either db/schema.rb or db/structure.sql, depending on `config.active_record.schema_format`)
rails db:schema:load                     # Loads a database schema file (either db/schema.rb or db/structure.sql, depending on `config.active_record.schema_format`) into the database
rails db:seed                            # Loads the seed data from db/seeds.rb
rails db:seed:replant                    # Truncates tables of each database for current environment and loads the seeds
rails db:setup                           # Creates the database, loads the schema, and initializes with the seed data (use db:reset to also drop the database first)
rails db:structure:dump                  # Dumps the database structure to db/structure.sql
rails db:structure:load                  # Recreates the databases from the structure.sql file
rails db:version                         # Retrieves the current schema version number
rails test:db                            # Run tests quickly, but also reset db
8 楼 已删除
需要 登录 后方可回复, 如果你还没有账号请 注册新账号