H2 Database - Unknown data type of MySQL script

vietsanto picture vietsanto · Nov 29, 2015 · Viewed 8.4k times · Source

I'm new in using in-memmory database.

I tried to use H2 database for developing project with spring boot, spring data JPA, but i got a problem when initialize application.

Caused by: org.h2.jdbc.JdbcSQLException: Unknown data type: "FK_PERSON__PERSONTYPE_IDX"; SQL statement:

Because this script was exported from MySQL. So i thinked there are some wrong syntax which H2 does not understand

For example, this is a part of script:

CREATE TABLE `person` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `firstname` varchar(255) NOT NULL,
  `lastname` varchar(255) DEFAULT NULL,
  `type` int(11) NOT NULL,
  `address` text,
  PRIMARY KEY (`id`),
  KEY `fk_person__persontype_idx` (`type`),
  CONSTRAINT `fk_person__persontype` FOREIGN KEY (`type`) REFERENCES `persontype` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='  ';

And i tried some solutions from these:

Convert MySQL script to H2

http://matthewcasperson.blogspot.de/2013/07/exporting-from-mysql-to-h2.html

Replace symbols with double quotes, single quotes,... even not use quote at all but not working. Please show me why? Thank you.

Answer

Søren picture Søren · Nov 2, 2018

I had a similar issue.

Removing the "KEY" line, which in your example corrosponds to:

KEY `fk_person__persontype_idx` (`type`),

worked for me.