Prisma deploy error
Describe the bug I have got an error while deploying prisma. I have created a very simple table in relationship which couldn't end in success. I tried multiple sources and multiple table definitions but I always got this error "Duplicate column name".
Database:mysql
type Contact @db(name: "contact") { id: Int! @id info: String! type: String! customerid: Customer }
type Customer @db(name: "customer") { id: Int! @id contact: [Contact] firstname: String! lastname: String! }
Error:
Contact (Type)
- Created type
Contact - Created field
idof typeInt! - Created field
infoof typeString! - Created field
typeof typeString! - Created field
customeridof typeCustomer
Customer (Type)
- Created type
Customer - Created field
idof typeInt! - Created field
contactof type[Contact!]! - Created field
firstnameof typeString! - Created field
lastnameof typeString!
ContactToCustomer (Relation)
- Created an inline relation between
ContactandCustomerin the columncustomeridof tableContact
Applying changes 27.9s
â–¸ The Migration failed and has not been performed. This is very likely not a transient issue.
â–¸ java.sql.SQLSyntaxErrorException: (conn=924) Duplicate column name 'customerid'
â–¸ at org.mariadb.jdbc.internal.util.exceptions.ExceptionMapper.get(ExceptionMapper.java:163)
â–¸ at org.mariadb.jdbc.internal.util.exceptions.ExceptionMapper.getException(ExceptionMapper.java:106)
â–¸ at org.mariadb.jdbc.MariaDbStatement.executeExceptionEpilogue(MariaDbStatement.java:235)
â–¸ at org.mariadb.jdbc.MariaDbPreparedStatementClient.executeInternal(MariaDbPreparedStatementClient.java:224)
â–¸ at org.mariadb.jdbc.MariaDbPreparedStatementClient.execute(MariaDbPreparedStatementClient.java:159)
â–¸ at com.zaxxer.hikari.pool.ProxyPreparedStatement.execute(ProxyPreparedStatement.java:44)
â–¸ at com.zaxxer.hikari.pool.HikariProxyPreparedStatement.execute(HikariProxyPreparedStatement.java)
â–¸ at slick.jdbc.StatementInvoker.results(StatementInvoker.scala:38)
â–¸ at slick.jdbc.StatementInvoker.iteratorTo(StatementInvoker.scala:21)
â–¸ at slick.jdbc.Invoker.first(Invoker.scala:30)
â–¸ at slick.jdbc.Invoker.first$(Invoker.scala:29)
â–¸ at slick.jdbc.StatementInvoker.first(StatementInvoker.scala:15)
â–¸ at slick.jdbc.StreamingInvokerAction$HeadAction.run(StreamingInvokerAction.scala:52)
â–¸ at slick.jdbc.StreamingInvokerAction$HeadAction.run(StreamingInvokerAction.scala:51)
â–¸ at slick.basic.BasicBackend$DatabaseDef$$anon$2.liftedTree1$1(BasicBackend.scala:275)
â–¸ at slick.basic.BasicBackend$DatabaseDef$$anon$2.run(BasicBackend.scala:275)
â–¸ at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
â–¸ at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
â–¸ at java.lang.Thread.run(Thread.java:748)
â–¸ Caused by: java.sql.SQLException: Duplicate column name 'customerid'
â–¸ Query is: ALTER TABLE testdb.contact
â–¸ ADD COLUMN customerid int NULL ,
â–¸ ADD FOREIGN KEY (customerid) REFERENCES testdb.customer(id) ON DELETE SET NULL;
â–¸
â–¸ at org.mariadb.jdbc.internal.util.LogQueryTool.exceptionWithQuery(LogQueryTool.java:146)
â–¸ at org.mariadb.jdbc.internal.protocol.AbstractQueryProtocol.executeQuery(AbstractQueryProtocol.java:217)
â–¸ at org.mariadb.jdbc.MariaDbPreparedStatementClient.executeInternal(MariaDbPreparedStatementClient.java:218)
â–¸ ... 15 more
â–¸ Expected behavior Should deploy model
Versions (please complete the following information):
- Connector: [
MySQL] - Prisma Server: [e.g.
1.34.0] prismaCLI: [e.g.prisma/1.34.1 (linux-x64) node-v10.16.0]- OS: [
Ubuntu 18.04]
Same happens to me
If possible, can you please try to rename the customerid column to something else, say, customer?
type Contact @db(name: "contact") {
id: Int! @id
info: String!
type: String!
customer: Customer
}
Do you have some more context for when this error is happening? I tried reproducing it on a fresh service and could not reproduce it.
if you introspect and there is the foreign key between the 2 tables the relationship shows in the generated model but when deploying it it tries to regenerate "alter" the table and add the relationship...idk why it's trying to alter when migrations is set to false.
Query is: ALTER TABLE portal_beta.publishers
ADD COLUMN source_id int NULL ,
ADD FOREIGN KEY (source_id) REFERENCES portal_beta.sources(id) ON DELETE SET NULL;
at org.mariadb.jdbc.internal.util.LogQueryTool.exceptionWithQuery(LogQueryTool.java:146)
at org.mariadb.jdbc.internal.protocol.AbstractQueryProtocol.executeQuery(AbstractQueryProtocol.java:217)
at org.mariadb.jdbc.MariaDbPreparedStatementClient.executeInternal(MariaDbPreparedStatementClient.java:218)
... 15 more
Same here
It actually doesn't matter whether there is a foreign key or not. For me it happens on any column. I chose a MySQL with existing data. Introspection and generation was fine but when deploying, it seems trying to recreate the whole table even though the structure already exists in the db. When I use the same model to create a fresh db, it works fine.
Prisma deploy error. Refer this post . https://www.prisma.io/forum/t/postgres-deploy-bug-on-existing-database/6802