rake db:migrate does nothing

2019-04-16 11:06发布

I'm following this tutorial, and I'm having a problem when running rake db:migrate

In db/migrate I have the create_post.rb file:

class CreatePosts < ActiveRecord::Migration
  def change
    create_table :posts do |t|
      t.string :title
      t.text :text
      t.timestamps
    end
  end
end

But it does not create the table. My database.yml file is:

development:
 adapter: mysql2
 encoding: utf8
 database: blog_development
 pool: 5
 username: root
 password:
 socket: /tmp/mysql.sock

The output from rake db:migrate seems ok.

I'm using phpMyAdmin to handle the database, which is correctly created manually by me.

What am I doing wrong?

2条回答
可以哭但决不认输i
2楼-- · 2019-04-16 11:35

If you are connecting to the right database everything seems fine to me.. I had a similar problem a few weeks ago and the accepted answer of this question fixed my issue.

Here are the steps to run:

rake db:drop:all
rake db:create:all
rake db:migrate

I hope it will fix your problem.

查看更多
Rolldiameter
3楼-- · 2019-04-16 11:55

Could you please tell which OS you got? Delete the line:

 socket: /tmp/mysql.sock

and run:

db:migrate

Give the output of:

db:migrate:status

If this is not working for you, you could also try to add:

host: 127.0.0.1

to your database.yml file

查看更多
登录 后发表回答