无法在Rails中使用Postgresql运行迁移

时间:2011-11-09 05:39:12

标签: ruby-on-rails-3 postgresql

我安装了postgresql并创建了一个数据库。当我运行rake db:migrate时,虽然我遇到以下错误:

[newuser@Freenaut flights1percent{master}]$ rake db:migrate --trace
** Invoke db:migrate (first_time)
** Invoke environment (first_time)
** Execute environment
** Execute db:migrate
== CreatePeople: migrating ===================================================
-- create_table(:people)
NOTICE: CREATE TABLE will create implicit sequence "people_id_seq" for serial column "people.id"
rake aborted!
An error has occurred, this and all later migrations canceled:

PGError: ERROR: relation "people" already exists
: CREATE TABLE "people" ("id" serial primary key, "created_at" timestamp, "updated_at" timestamp) 

这是一个奇怪的错误,因为错误消息表明此表已存在。但是,我知道它不应该像我刚创建数据库那样。那么这里出了什么问题?

1 个答案:

答案 0 :(得分:1)

除非表确实存在,否则不会发生这种情况。可能是您在运行迁移之前将表创建为测试的一部分吗?

我在8.4分贝上运行你的创建表,这就是我得到的:

CREATE TABLE "people" ("id" serial primary key, "created_at" timestamp, "updated_at" timestamp);
   NOTICE:  CREATE TABLE will create implicit sequence "people_id_seq" for serial column "people.id"
NOTICE:  CREATE TABLE / PRIMARY KEY will create implicit index "people_pkey" for table "people"
CREATE TABLE

然后我再次运行它并收到您所做的相同错误消息:

CREATE TABLE "people" ("id" serial primary key, "created_at" timestamp, "updated_at" timestamp);
NOTICE:  CREATE TABLE will create implicit sequence "people_id_seq1" for serial column "people.id"
ERROR:  relation "people" already exists