简体   繁体   中英

db:migrate does not create tables

Working with:

  • Ruby 1.9.3
  • Rails 4
  • MySQL 5.6

Whenever I run "rake db:migrate" no tables are created in the database.

I have created a database and named it "simple_cms_development" and changed the development part of "database.yml" accordingly:

development:
  adapter: sqlite3
  database: simple_cms_development
  pool: 5
  username: simple_cms
  password: ruby
  timeout: 5000

I generated and model named "User" and edited "create_users.rb" to:

class CreateUsers < ActiveRecord::Migration
  def change
    create_table :users do |t|
      t.string "first_name", :limit => 25
      t.string "last_name", :limit => 50
      t.string "email", :default => "", :null => false
      t.string "password", :limit => 40
      t.timestamps
    end
  end
end

I run "rake db:migrate" and there is no change to the tables within the database. When I run SHOW TABLES; in MySQL I get back "Empty set (0.00sec)". I don't even get "schema_migrations" table.

Any ideas what is going on?

Thanks!

Your database.yml is set up to use sqlite3, not mySQL. Yours is now this:

development:
  adapter: sqlite3
  database: simple_cms_development
  pool: 5
  username: simple_cms
  password: ruby
  timeout: 5000

You should probably be using the mySQL2 gem , and your database.yml should look something like this:

development:
  adapter: mysql2 
  encoding: utf8
  reconnect: false
  database: simple_cms_development
  pool: 5
  username: root
  password: your-password
  socket: /var/run/mysqld/mysqld.sock

According to this StackOverflow discussion you can get your socket by running

mysqladmin variables | grep socket

or if you have a password on your root:

mysqladmin password-here variables | grep socket`

If you want to use host and port instead of socket try this:

development:
  adapter: mysql2 
  encoding: utf8
  reconnect: false
  database: simple_cms_development
  pool: 5
  username: root
  password: your-password
  host: 127.0.0.1
  port: 3306

Here is a blog with instructions on how to set up mySQL with Rails 3.2, it might help with your Rails 4 issue: http://cicolink.blogspot.com/2011/06/how-to-install-ruby-on-rails-3-with.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM