我正在使用 MySQL Server 5.7 ,在 Windows 7 64 上通过Lynda.com完成教程 Ruby on Rails 3 Essential Training > MySQL Connector C 6.1 6.1.2 , Ruby 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 aborted!
不知道如何构建任务'db:schema:dump'
(通过使用--trace运行任务查看完整跟踪)
我花了最后24小时卸载,下载和重新安装多个版本的Ruby,Rails,MySQL服务器和连接器,花费了我最长的时间用于学习如何添加安装MySQL2 gem我通过下载完成旧版本 mysql 0.2.6 。
尽管如此,该中止消息仍保持不变。
此外,当我在此处输入rake -T
时,没有数据库耙子显示:
rake about
rake assets:clean [keep]
rake assets:clobber
rake assets:environment
rake assets:precompile
rake cache_digests:dependencies
rake cache_digests:nested_dependencies
(db应显示但不显示)
rake doc:app
...
rake test:all:db
...
rake tmp:create
帮助吗 的
按要求提供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]
答案 0 :(得分:0)
在文件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
)。
评论:您没有db:
rake -T
命令,因此问题出在其他地方。
答案 1 :(得分:0)
您将收到此错误
~/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)
因为您的rails应用程序中不包含active_record
将以下行添加到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