prisma1 icon indicating copy to clipboard operation
prisma1 copied to clipboard

Prisma deploy error

Open BucketLst opened this issue 7 years ago • 7 comments

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 id of type Int!
  • Created field info of type String!
  • Created field type of type String!
  • Created field customerid of type Customer

Customer (Type)

  • Created type Customer
  • Created field id of type Int!
  • Created field contact of type [Contact!]!
  • Created field firstname of type String!
  • Created field lastname of type String!

ContactToCustomer (Relation)

  • Created an inline relation between Contact and Customer in the column customerid of table Contact

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]
  • prisma CLI: [e.g. prisma/1.34.1 (linux-x64) node-v10.16.0]
  • OS: [Ubuntu 18.04]

BucketLst avatar Jul 08 '19 17:07 BucketLst

Same happens to me

marcus-sa avatar Jul 15 '19 07:07 marcus-sa

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
}

divyenduz avatar Jul 19 '19 08:07 divyenduz

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.

do4gr avatar Jul 19 '19 13:07 do4gr

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

rgauny avatar Aug 15 '19 17:08 rgauny

Same here

greguintow avatar Sep 16 '19 01:09 greguintow

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.

JonathanStoye avatar Sep 24 '19 21:09 JonathanStoye

Prisma deploy error. Refer this post . https://www.prisma.io/forum/t/postgres-deploy-bug-on-existing-database/6802

ruhankhandakar avatar Feb 18 '20 09:02 ruhankhandakar