【问题标题】:Rake Aborted: db:schema:dumpRake 中止:db:schema:dump
【发布时间】:2013-12-20 20:35:43
【问题描述】:

我正在通过 Lynda.com 在 Windows 7 64 上使用 MySQL Server 5.7 完成教程 Ruby on Rails 3 Essential TrainingMySQL 连接器 C 6.1 6.1.2Ruby 1.9.3p392 (2013-02-22) [i386-mingw32]Rails 4.0.2

在培训中,我在“数据库和迁移”部分尝试将我在 MySQL 中创建的数据库与我的 Rails 项目同步,但是我遇到了中止消息。

讲师要求我的班级通过命令提示符打开我们的 rails 项目并执行 Rake 以使用以下代码构建“schema.rb”:

$ rake db:schema:dump

这个中止消息是每次我输入该代码时的结果:

C:\Users\User\Documents\simple_cms>rake db:schema:dump

rake 中止!

不知道如何构建任务'db:schema:dump'

(通过使用 --trace 运行任务查看完整跟踪)

在过去的 24 小时里,我一直在卸载、下载和重新安装多个版本的 Ruby、Rails、MySQL 服务器和连接器,其中大部分时间都花在学习如何添加安装 MySQL2 gem 上,我通过下载一个旧版本 mysql 0.2.6.

尽管如此,该中止消息一直保持不变。

此外,当我输入 rake -T 时,没有 DB 耙子显示,如您在此处看到的:

扫一扫

rake assets:clean[keep]

rake assets:clobber

耙资产:环境

rake 资产:预编译

rake cache_digests:依赖项

rake cache_digests:nested_dependencies

(db 应该显示但不显示的位置)

rake 文档:应用程序

...

rake test:all:db

...

rake tmp:创建

帮助?


根据要求提供 Gem 文件

source '...'

# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.0.2'

# Use mysql as the database for Active Record
gem 'mysql2'

# Use SCSS for stylesheets
gem 'sass-rails', '~> 4.0.0'

# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'

# Use CoffeeScript for .js.coffee assets and views
gem 'coffee-rails', '~> 4.0.0'

# See ... for more supported runtimes
# gem 'therubyracer', platforms: :ruby

# Use jquery as the JavaScript library
gem 'jquery-rails'

# Turbolinks makes following links in your web application faster. Read more: ...
gem 'turbolinks'

# Build JSON APIs with ease. Read more: ...
gem 'jbuilder', '~> 1.2'

group :doc do
  # bundle exec rake doc:rails generates the API under doc/api.
  gem 'sdoc', require: false
end

# Use ActiveModel has_secure_password
# gem 'bcrypt-ruby', '~> 3.1.2'

# Use unicorn as the app server
# gem 'unicorn'

# Use Capistrano for deployment
# gem 'capistrano', group: :development

# Use debugger
# gem 'debugger', group: [:development, :test]

【问题讨论】:

  • 你必须在某处分享你正在使用的代码,比如GitHub,从这样的教程中很难弄清楚。
  • 你需要共享你的 Gemfile 并确保你已经运行了:bundle install,看起来它不知道要使用哪个数据库,希望你没有像这样创建项目:rails new appname --skip-active-record 不会在 Rails 中为您提供与 db 相关的内容
  • @bjhaid 我刚刚将 GemFile 添加到上面的问题中
  • @BakariPace 你运行“捆绑安装”了吗??
  • 您是否尝试过运行并--trace 标记?如果是,请向我们展示转储!

标签: mysql ruby-on-rails ruby ruby-on-rails-3 rake


【解决方案1】:

在文件 database.yml 中,你应该有类似的内容:

default: &default
  adapter: mysql2
  encoding: utf8
  database: simple_cms_development
  pool: 5
  username: simple_cms
  password: secretpassword
  socket: /tmp/mysql.sock

development:
  <<: *default
  database: simple_cms_development

您也许应该检查database 在您的实际环境中是否正确定义 (development)。

评论:rake -T 命令中没有任何db:,所以问题出在其他地方。

【讨论】:

    【解决方案2】:

    你会得到这个错误

    ~/Project$ rake db:schema:dump
    rake aborted!
    Don't know how to build task 'db:schema:dump'
    (See full trace by running task with --trace)
    

    因为 active_record 不包含在您的 rails 应用程序中

    将以下行添加到application.rb

    require "active_record/railtie"
    

    现在试试,

    ~/Project$ rake -T
    

    你应该可以看到 rake db 命令

    $ rails -T
    rails about                              # List versions of all Rails frameworks and the environment
    rails assets:clean[keep]                 # Remove old compiled assets
    rails assets:clobber                     # Remove compiled assets
    rails assets:environment                 # Load asset compile environment
    rails assets:precompile                  # Compile all the assets named in config.assets.precompile
    rails cache_digests:dependencies         # Lookup first-level dependencies for TEMPLATE (like messages/show or comments/_com...
    rails cache_digests:nested_dependencies  # Lookup nested dependencies for TEMPLATE (like messages/show or comments/_comment....
    rails db:create                          # Creates the database from DATABASE_URL or config/database.yml for the current RAI...
    rails db:drop                            # Drops the database from DATABASE_URL or config/database.yml for the current RAILS...
    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:status                  # Display status of migrations
    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.dump file
    rails db:schema:cache:dump               # Creates a db/schema_cache.dump file
    rails db:schema:dump                     # Creates a db/schema.rb file that is portable against any DB supported by Active R...
    rails db:schema:load                     # Loads a schema.rb file into the database
    rails db:seed                            # Loads the seed data from db/seeds.rb
    rails db:setup                           # Creates the databa
    

    【讨论】:

      猜你喜欢
      • 2016-10-02
      • 1970-01-01
      • 1970-01-01
      • 2014-04-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-08-04
      • 2016-10-25
      相关资源
      最近更新 更多