Choub890
Choub890

Reputation: 1163

Error with Persistent syntax using MySQL and Yesod

I am currently building a website using Haskell and the Yesod platform, and a MySQL database. I would like to make use of the Persistent module within Yesod. To do so, I have followed the guide on this module. Everything worked, until I wanted to add a default value to the accountCreatedDate column in my database. Here is my models file:

User
    idAccount AccountId Int
    userLastName Text Maybe
    userFirstName Text Maybe
    userAge Int Maybe
    userSex Text Maybe
    userEMail Text
    UniqueUserEMail userEMail
Account
    accountName Text
    accountPassword Text
    accountCreatedDate UTCTime default=CURRENT_TIME
    accountLastLogin UTCTime
    UniqueAccountName accountName

When I run yesod devel, I get the following error:

devel.hs: ConnectionError {errFunction = "query", errNumber = 1064, errMessage = "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'CURRENT_TIME' at line 1"} Exit code: ExitFailure 1

What I find weird about this error, is that I have copied the guide for that exact line (except the name of the column). What do I have to change in order to fix this problem?

EDIT: I have also tried CURRENT_TIME().

EDIT2: My current MySQL version is 5.5 and this is the query Yesod is trying to do:

CREATe TABLE `account`(`id` BIGINT NOT NULL AUTO_INCREMENT PRIMARY KEY,`account_name` TEXT CHARACTER SET utf8 NOT NULL,`account_password` TEXT CHARACTER SET utf8 NOT NULL,`account_created_date` DATETIME NOT NULL DEFAULT CURRENT_TIME,`account_last_login` DATETIME NOT NULL)

Upvotes: 1

Views: 530

Answers (1)

Choub890
Choub890

Reputation: 1163

After some more research, it seems that it is not possible to set a default value using a function like CURRENT_TIME with my version of MySQL for a DateTime column. Since UTCTime in Yesod/Persistent is a DateTime, I guess I cannot do this. It seems however that his is possible with MySQL 5.6.5.

I have found the information on the following link: How do you set a default value for a MySQL Datetime column?

Upvotes: 1

Related Questions