问题
I'm using Yesod and Persistent to make a blog (really original, eh?).
At some point, I changed my model, and Persistent said that what I was trying to do is unsafe, and that I would have to do it manually. It said:
Database migration: manual intervention required.
The following actions are considered unsafe:
ALTER TABLE "article" DROP COLUMN "date";
So I went ahead and ran that in Postgres. In fact, I have gone ahead and dropped the table "article", and I get the error:
Migrating: CREATe TABLE "article"
( "id" SERIAL PRIMARY KEY UNIQUE,
"title" VARCHAR NOT NULL,
"author" VARCHAR NOT NULL,
"day" DATE NOT NULL DEFAULT DATE,
"content" VARCHAR NOT NULL)
devel.hs: SqlError { sqlState = "42703"
, sqlExecStatus = FatalError
, sqlErrorMsg = "column \"date\" does not exist"
, sqlErrorDetail = ""
, sqlErrorHint = ""
}
Here is how the schema currently looks (as defined using Persistent):
-- Blog Article
Article
title Text
author Text
day Day default=DATE
content MathJax
What is going on here? What do I have to do to get Postgres and Persistent back in sync?
回答1:
please change your create table code to :
digoal=# CREATE TABLE "article"
( "id" SERIAL PRIMARY KEY UNIQUE,
"title" VARCHAR NOT NULL,
"author" VARCHAR NOT NULL,
"day" DATE NOT NULL DEFAULT current_date,
"content" VARCHAR NOT NULL);
CREATE TABLE
PostgreSQL no DATA function, so you can use current_date instead.
回答2:
I'm answering my own question because digoal's solution wasn't exactly right, but he got the main idea right, so he deserves the karma. But the real solution is too big for a comment. Basically, I did have a problem in my Persistent schema. As digoal said, Postgres does not have a 'date' function. It does have 'current_date'. So the new Persistent schema looks like:
-- Blog Article
Article
title Text
author Text
day Day default=CURRENT_DATE
content MathJax
来源:https://stackoverflow.com/questions/23004528/haskell-persistent-out-of-sync