2017-03-28 13 views
3

Yesod를 실행하고 MySQL 데이터베이스에 액세스하고 있습니다.Yesod 데이터베이스 마이그레이션 루프

내 모델은 다음과 같습니다

Starting devel application 
Migrating: ALTER TABLE `user` ALTER COLUMN `password` DROP DEFAULT 
28/Mar/2017:23:46:44 +0200 [Debug#SQL] ALTER TABLE `user` ALTER COLUMN `password` DROP DEFAULT; [] 
devel.hs: ConnectionError {errFunction = "query", errNumber = 1101, errMessage = "BLOB/TEXT column 'password' can't have a default value"} 
Unexpected: child process exited with ExitFailure 1 
Trying again 
Starting devel application 
Migrating: ALTER TABLE `user` ALTER COLUMN `password` DROP DEFAULT 
28/Mar/2017:23:46:46 +0200 [Debug#SQL] ALTER TABLE `user` ALTER COLUMN `password` DROP DEFAULT; [] 
devel.hs: ConnectionError {errFunction = "query", errNumber = 1101, errMessage = "BLOB/TEXT column 'password' can't have a default value"} 
Unexpected: child process exited with ExitFailure 1 
Trying again 

그것은 끝없는 루프로 간다 :

User 
    ident Text 
    password Text Maybe 
    UniqueUser ident 
    deriving Typeable 
Email 
    email Text 
    userId UserId Maybe 
    verkey Text Maybe 
    UniqueEmail email 
Comment json -- Adding "json" causes ToJSON and FromJSON instances to be derived. 
    message Text 
    userId UserId Maybe 
    deriving Eq 
    deriving Show 

-- By default this file is used in Model.hs (which is imported by Foundation.hs) 

나는 Yesod 응용 프로그램을 실행하면 다음과 같은 반복합니다.

runLoggingT (runSqlPool (runMigration migrateAll) pool) logFunc 

하지만 해결 방법을 사용하는 경우, 내가 다른 오류 얻을 :

28/Mar/2017:23:56:28 +0200 [Error#yesod-core] Foundation.hs:(137,5)-(144,45): Non-exhaustive patterns in function isAuthorized 
@(yesod-core-1.4.32-6HthMZNCl0sEMRz6GJ4QO1:Yesod.Core.Class.Yesod ./Yesod/Core/Class/Yesod.hs:693:5) 
28/Mar/2017:23:56:28 +0200 [Debug#SQL] SELECT `ident`,`password` FROM `user` WHERE `id`=? ; [PersistInt64 1] 
GET /test 
    Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8 
    Status: 500 Internal Server Error 0.006514s 

답변

2

Text Maybe 열에 default=NULL을 추가하면이 문제가 해결됩니다. 일부 MySQL 버전에서는 sqltype=varchar(255)을 추가하여 열 유형을 변경해야합니다. 귀하의 경우 모델은 다음과 같아야합니다.

User 
    ident Text 
    password Text Maybe sqltype=varchar(255) default=NULL 
    UniqueUser ident 
    deriving Typeable 
Email 
    email Text 
    userId UserId Maybe 
    verkey Text Maybe sqltype=varchar(255) default=NULL 
    UniqueEmail email 
Comment json -- Adding "json" causes ToJSON and FromJSON instances to be derived. 
    message Text 
    userId UserId Maybe 
    deriving Eq 
    deriving Show 

-- By default this file is used in Model.hs (which is imported by Foundation.hs) 
2

그것은 관련 this bug 것 같아를

해결 방법은 사용하지 않도록 데이터베이스 마이그레이션을 의미 Application.hs에서 다음 줄을 주석입니다 마이그레이션 및 기본값으로.

this workaround을 사용하면 MySQL의 동작을 기본값으로 변경하거나 text에서 varchar으로 열 유형을 변경해보십시오.

+0

고맙습니다! 그것을 사용하여 해결 :'alter table user modify column password varchar (255) default '';' –