title: Getting message "Attempt to define a second primary key". When running @DataJpaTest
body: <p>I don't know exactly why, but I am getting this message from Flyway evolution in H2 database. It's a <strong>@DataJpaTest</strong> spring boot test.</p>
  
  <p>Seems like some dialect stuff is not being respected.</p>
  
  <p><strong>Attempt to define a second primary key; SQL statement:</strong></p>
  
  <pre><code>@RunWith(SpringRunner.class)
  @DataJpaTest
  @FlywayTest
  
  public class ParagraphStoreTest {
  
  @Autowired
  private TestEntityManager entityManager;
  
  @Autowired
  private ParagraphStore paragraphStore;
  
  @Test
  public void testExample() throws Exception {
  
      long scanId = 123;
      long userId = 1234;
      int minParagraphLength = 1;
      int pageNumber = 1;
      int pageSize = 50;
  
      Pageable pageable = new PageRequest(pageNumber, pageSize, Direction.ASC, "paragraphIndex");
  
      this.entityManager.persist(Paragraph.builder().scan(Scan.builder().id(scanId).urlId(userId).build())
              .paragraphIndex(1).wordCount(1));
  
      Page&lt;Paragraph&gt; paragraphs = this.paragraphStore.findAllParagraphStatsByScanIdLimit(scanId, userId,
              minParagraphLength, pageable);
  
      assertNotNull(paragraphs);
  }
  
  }
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/B6kmJ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/B6kmJ.png" alt="application.yml"></a></p>
  
  <p>Exception</p>
  
  <pre><code>    rror starting ApplicationContext. To display the auto-configuration report re-run your application with 'debug' enabled.
  2017-06-30 16:21:32 [main] ERROR o.s.boot.SpringApplication - Application startup failed
  org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'flywayInitializer' defined in class path resource [org/springframework/boot/autoconfigure/flyway/FlywayAutoConfiguration$FlywayConfiguration.class]: Invocation of init method failed; nested exception is org.flywaydb.core.internal.dbsupport.FlywaySqlScriptException: 
  
  Migration V1__Init.sql failed
  -----------------------------
  SQL State  : 90017
  Error Code : 90017
  Message    : Attempt to define a second primary key; SQL statement:
  CREATE TABLE users (
      id serial NOT NULL,
      user_name varchar(160) NOT NULL,
      user_pass varchar(160) NOT NULL,
      first_name varchar(160) NULL,
      last_name varchar(160) NULL,
      last_sign_in date NULL,
      preferences text NOT NULL DEFAULT '{}'::text,
      CONSTRAINT users_pkey PRIMARY KEY (user_name)
  ) [90017-148]
  Location   : db/migration/V1__Init.sql (C:\Users\victo\Documents\dev\projects\readability-dev\bin\db\migration\V1__Init.sql)
  Line       : 1
  Statement  : CREATE TABLE users (
      id serial NOT NULL,
      user_name varchar(160) NOT NULL,
      user_pass varchar(160) NOT NULL,
      first_name varchar(160) NULL,
      last_name varchar(160) NULL,
      last_sign_in date NULL,
      preferences text NOT NULL DEFAULT '{}'::text,
      CONSTRAINT users_pkey PRIMARY KEY (user_name)
  )
  
  at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1628)
  at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:555)
  at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483)
  at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
  at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
  at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
  at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
  at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:296)
  at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
  at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1081)
  at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:856)
  at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:542)
  at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:737)
  at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:370)
  at org.springframework.boot.SpringApplication.run(SpringApplication.java:314)
  at org.springframework.boot.test.context.SpringBootContextLoader.loadContext(SpringBootContextLoader.java:120)
  at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.java:98)
  at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:116)
  at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:83)
  at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.injectDependencies(DependencyInjectionTestExecutionListener.java:117)
  at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.prepareTestInstance(DependencyInjectionTestExecutionListener.java:83)
  at org.springframework.boot.test.autoconfigure.SpringBootDependencyInjectionTestExecutionListener.prepareTestInstance(SpringBootDependencyInjectionTestExecutionListener.java:44)
  at org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:230)
  at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTest(SpringJUnit4ClassRunner.java:228)
  at org.springframework.test.context.junit4.SpringJUnit4ClassRunner$1.runReflectiveCall(SpringJUnit4ClassRunner.java:287)
  at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
  at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.methodBlock(SpringJUnit4ClassRunner.java:289)
  at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:247)
  at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:94)
  at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
  at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
  at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
  at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
  at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
  at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
  at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)
  at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
  at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:191)
  at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)
  at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
  at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
  at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:678)
  at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
  at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
  Caused by: org.flywaydb.core.internal.dbsupport.FlywaySqlScriptException: 
  </code></pre>
  
  <p>User.java</p>
  
  <pre><code>@Entity
  @Table(name="users")
  @AllArgsConstructor(access = AccessLevel.PROTECTED)
  
  @NoArgsConstructor
  
  @ToString(callSuper=true)
  @Builder
  public class User {
  
  @Id
  @Getter @Setter
  @GeneratedValue(strategy=GenerationType.SEQUENCE, generator="users_id_seq")
  @SequenceGenerator(name="users_id_seq", sequenceName="users_id_seq")
  private Long id;
  
  @Getter @Setter
  private String socialId;
  
  @Getter @Setter
  private boolean IsEmailActivationRequired;
  
  @Getter @Setter
  private String firstName;
  
  @Getter @Setter
  private String lastName;
  
  @Getter @Setter
  private String userName;
  
  @Getter @Setter
  private String userPass;
  
  @Email
  @NotNull
  @NotEmpty
  @Getter @Setter
  private String userEmail;
  
  }
  </code></pre>