sqlite - 迁移待定。要解决此问题,请在本地运行 : bin/rake db:migrate RAILS_ENV=development, 工作

标签 sqlite ruby-on-rails-4 docker amazon-ec2 docker-compose

我有一个奇怪的错误一直困扰着我一段时间。当我在本地运行服务器时,站点显示完美,但是当我尝试在我的 aws EC2 上访问它时,我收到错误“ActiveRecord::PendingMigrationError
迁移待定。要解决此问题,请运行:bin/rake db:migrate RAILS_ENV=development"
所以我运行了命令“bin/rake db:migrate RAILS_ENV=development”并打印出来。

bin/rake db:migrate RAILS_ENV=development
Running via Spring preloader in process 30908
== 20160812175638 CreatePosts: migrating ======================================
-- create_table(:posts)
   -> 0.0014s
== 20160812175638 CreatePosts: migrated (0.0017s) =============================

== 20160813194710 DeviseCreateUsers: migrating ================================
-- create_table(:users)
   -> 0.0015s
-- add_index(:users, :email, {:unique=>true})
   -> 0.0005s
-- add_index(:users, :reset_password_token, {:unique=>true})
   -> 0.0007s
== 20160813194710 DeviseCreateUsers: migrated (0.0031s) =======================

== 20160912112653 AddAttachmentImageToPosts: migrating ========================
-- change_table(:posts)
   -> 0.0012s
== 20160912112653 AddAttachmentImageToPosts: migrated (0.0013s) ===============

但我仍然得到相同的消息。所以我在网上做了一些搜索,我已经阅读了关于这个问题的所有页面,但一无所获。

当我运行“rake db:migrate:status”时,我看到了这个:
Status   Migration ID    Migration Name
--------------------------------------------------
   up     20160812175638  Create posts
   up     20160813194710  Devise create users
   up     20160912112653  Add attachment image to posts

当我执行“rake db:version”时,我得到了这个:
Current version: 20160912112653

“rails -v”给了我
Rails 4.2.6

并且“cat Gemfile | grep rails”给了我这个:# Bundle edge Rails 代替:
gem 'rails', github: 'rails/rails'
gem 'rails'
gem 'sass-rails', '~> 5.0'
gem 'coffee-rails', '~> 4.1.0'
# See https://github.com/rails/execjs#readme for more supported runtimes
gem 'jquery-rails'
# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
# bundle exec rake doc:rails generates the API under doc/api.
# gem 'capistrano-rails', group: :development
  # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring

我在这里不知所措,它在本地工作得很好,如果我从 database.rb 文件中编辑掉/data/,它工作得很好。
default: &default
  adapter: sqlite3
  pool: 5
  timeout: 5000

development:
  <<: *default
  database: db/data/development.sqlite3
test:
  <<: *default
  database: db/test.sqlite3

production:
  <<: *default
  database: db/data/production.sqlite3

但是,如果我这样做,一旦我使用为我运行 docker-compose 的重新部署脚本更新站点,数据库就会被删除。

我很确定我错过了一个简单的事情,它给了我这个错误,因为该站点确实在本地主机上工作。

//猛犸象

我想我知道现在是什么问题,不知道如何解决它。
当我运行 docker volume ls它根本找不到任何音量。
这是 docker inspect 的输出
[
    {
        "Id": "4b72d9a721f086706f53f08a88b5f32c959f6a28ec37d3396c14922c7750bc48",
        "Created": "2016-10-09T16:48:24.678289811Z",
        "Path": "rails",
        "Args": [
            "server",
            "-b",
            "0.0.0.0"
        ],
        "State": {
            "Status": "running",
            "Running": true,
            "Paused": false,
            "Restarting": false,
            "OOMKilled": false,
            "Dead": false,
            "Pid": 15188,
            "ExitCode": 0,
            "Error": "",
            "StartedAt": "2016-10-09T16:48:24.925986705Z",
            "FinishedAt": "0001-01-01T00:00:00Z"
        },
        "Image": "sha256:c8ccdcb3602d581c06264db2b24f99cd4f936713ca84c614c056743b8d89d459",
        "ResolvConfPath": "/var/lib/docker/containers/4b72d9a721f086706f53f08a88b5f32c959f6a28ec37d3396c14922c7750bc48/resolv.conf",
        "HostnamePath": "/var/lib/docker/containers/4b72d9a721f086706f53f08a88b5f32c959f6a28ec37d3396c14922c7750bc48/hostname",
        "HostsPath": "/var/lib/docker/containers/4b72d9a721f086706f53f08a88b5f32c959f6a28ec37d3396c14922c7750bc48/hosts",
        "LogPath": "/var/lib/docker/containers/4b72d9a721f086706f53f08a88b5f32c959f6a28ec37d3396c14922c7750bc48/4b72d9a721f086706f53f08a88b5f32c959f6a28ec37d3396c14922c7750bc48-json.log",
        "Name": "/juridik_app_1",
        "RestartCount": 0,
        "Driver": "aufs",
        "MountLabel": "",
        "ProcessLabel": "",
        "AppArmorProfile": "",
        "ExecIDs": null,
        "HostConfig": {
            "Binds": [
                "/storage/db:/usr/src/app/db/data:rw"
            ],
            "ContainerIDFile": "",
            "LogConfig": {
                "Type": "json-file",
                "Config": {}
            },
            "NetworkMode": "default",
            "PortBindings": {
                "3000/tcp": [
                    {
                        "HostIp": "",
                        "HostPort": "80"
                    }
                ]
            },
            "RestartPolicy": {
                "Name": "always",
                "MaximumRetryCount": 0
            },
            "AutoRemove": false,
            "VolumeDriver": "",
            "VolumesFrom": [],
            "CapAdd": null,
            "CapDrop": null,
            "Dns": null,
            "DnsOptions": null,
            "DnsSearch": null,
            "ExtraHosts": null,
            "GroupAdd": null,
            "IpcMode": "",
            "Cgroup": "",
            "Links": null,
            "OomScoreAdj": 0,
            "PidMode": "",
            "Privileged": false,
            "PublishAllPorts": false,
            "ReadonlyRootfs": false,
            "SecurityOpt": null,
            "UTSMode": "",
            "UsernsMode": "",
            "ShmSize": 67108864,
            "Runtime": "runc",
            "ConsoleSize": [
                0,
                0
            ],
            "Isolation": "",
            "CpuShares": 0,
            "Memory": 0,
            "CgroupParent": "",
            "BlkioWeight": 0,
            "BlkioWeightDevice": null,
            "BlkioDeviceReadBps": null,
            "BlkioDeviceWriteBps": null,
            "BlkioDeviceReadIOps": null,
            "BlkioDeviceWriteIOps": null,
            "CpuPeriod": 0,
            "CpuQuota": 0,
            "CpusetCpus": "",
            "CpusetMems": "",
            "Devices": null,
            "DiskQuota": 0,
            "KernelMemory": 0,
            "MemoryReservation": 0,
            "MemorySwap": 0,
            "MemorySwappiness": -1,
            "OomKillDisable": false,
            "PidsLimit": 0,
            "Ulimits": null,
            "CpuCount": 0,
            "CpuPercent": 0,
            "IOMaximumIOps": 0,
            "IOMaximumBandwidth": 0
        },
        "GraphDriver": {
            "Name": "aufs",
            "Data": null
        },
        "Mounts": [
            {
                "Source": "/storage/db",
                "Destination": "/usr/src/app/db/data",
                "Mode": "rw",
                "RW": true,
                "Propagation": "rprivate"
            }
        ],
        "Config": {
            "Hostname": "4b72d9a721f0",
            "Domainname": "",
            "User": "",
            "AttachStdin": false,
            "AttachStdout": false,
            "AttachStderr": false,
            "ExposedPorts": {
                "3000/tcp": {}
            },
            "Tty": false,
            "OpenStdin": false,
            "StdinOnce": false,
            "Env": [
                "S3_BUCKET_REGION=eu-europe-1",
                "S3_SECRET_KEY=*************************",
                "S3_BUCKET=juridik-assets",
                "S3_KEY_ID=*********************",
                "PATH=/usr/local/bundle/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
                "RUBY_MAJOR=2.3",
                "RUBY_VERSION=2.3.1",
                "RUBY_DOWNLOAD_SHA256=b87c738cb2032bf4920fef8e3864dc5cf8eae9d89d8d523ce0236945c5797dcd",
                "RUBYGEMS_VERSION=2.6.6",
                "BUNDLER_VERSION=1.13.1",
                "GEM_HOME=/usr/local/bundle",
                "BUNDLE_PATH=/usr/local/bundle",
                "BUNDLE_BIN=/usr/local/bundle/bin",
                "BUNDLE_SILENCE_ROOT_WARNING=1",
                "BUNDLE_APP_CONFIG=/usr/local/bundle"
            ],
            "Cmd": [
                "rails",
                "server",
                "-b",
                "0.0.0.0"
            ],
            "Image": "juridik_app",
            "Volumes": {
                "/usr/src/app/db/data": {}
            },
            "WorkingDir": "/usr/src/app",
            "Entrypoint": null,
            "OnBuild": null,
            "Labels": {
                "com.docker.compose.config-hash": "6c31573cdfdba0b4c056f7af83e652b728c4a56083a6c7eabd8634b2dbfccb47",
                "com.docker.compose.container-number": "1",
                "com.docker.compose.oneoff": "False",
                "com.docker.compose.project": "juridik",
                "com.docker.compose.service": "app",
                "com.docker.compose.version": "1.8.0"
            }
        },
        "NetworkSettings": {
            "Bridge": "",
            "SandboxID": "de9a9bfc8196ee65d89e09dc0a41acbb1f28830229d4e53fe057832a5419a778",
            "HairpinMode": false,
            "LinkLocalIPv6Address": "",
            "LinkLocalIPv6PrefixLen": 0,
            "Ports": {
                "3000/tcp": [
                    {
                        "HostIp": "0.0.0.0",
                        "HostPort": "80"
                    }
                ]
            },
            "SandboxKey": "/var/run/docker/netns/de9a9bfc8196",
            "SecondaryIPAddresses": null,
            "SecondaryIPv6Addresses": null,
            "EndpointID": "ee42a322ee7de01529408d782a93556333cf9e368934ccfe03e98c1223ae44e3",
            "Gateway": "172.17.0.1",
            "GlobalIPv6Address": "",
            "GlobalIPv6PrefixLen": 0,
            "IPAddress": "172.17.0.2",
            "IPPrefixLen": 16,
            "IPv6Gateway": "",
            "MacAddress": "02:42:ac:11:00:02",
            "Networks": {
                "bridge": {
                    "IPAMConfig": null,
                    "Links": null,
                    "Aliases": null,
                    "NetworkID": "16145185c61bbe11c565fbbb974aefaa79db796feb80eccb98765fc67bed8158",
                    "EndpointID": "ee42a322ee7de01529408d782a93556333cf9e368934ccfe03e98c1223ae44e3",
                    "Gateway": "172.17.0.1",
                    "IPAddress": "172.17.0.2",
                    "IPPrefixLen": 16,
                    "IPv6Gateway": "",
                    "GlobalIPv6Address": "",
                    "GlobalIPv6PrefixLen": 0,
                    "MacAddress": "02:42:ac:11:00:02"
                }
            }
        }
    }
]

最佳答案

在网上搜索了大约 3 天的答案后,我从我的 friend 那里得到了一个答案。

他告诉我摆脱“等待迁移”的大红色错误消息
我必须做

docker-compose exec app bash

在里面做
rake db:migrate

进而
exit

我做了什么,然后我的问题就消失了。所以它现在可以正常工作了。希望其他人也能从中受益。

关于sqlite - 迁移待定。要解决此问题,请在本地运行 : bin/rake db:migrate RAILS_ENV=development, 工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39904733/

相关文章:

android - 关于Android中SQLite数据库游标的几个问题

java - Android ListView不显示数据库信息

ruby-on-rails-4 - 将Rails 4 has_many从proc条件转换为where

php - PECL 包在 Docker 中安装失败

ios - 设置 iPhone 模拟器目录和 Xcode 派生数据目录

database - 选择然后插入sqlite表

javascript - 在特定页面上执行 javascript 的正确 "Rails"方法

javascript - 错误请求,错误 URI 400 错误

docker - 远程 Docker 端口转发

docker - docker 中的 Eureka 客户端未与 Eureka 服务器连接