代码之家  ›  专栏  ›  技术社区  ›  Maciaz

每次启动应用程序时,spring data.sql文件都会添加一个新记录。

  •  1
  • Maciaz  · 技术社区  · 6 年前

    这是我的 application.properties 文件:

    spring.datasource.url= jdbc:postgresql://localhost:5432/Crypto
    spring.datasource.username=postgres
    spring.datasource.password=wololo
    spring.jpa.hibernate.ddl-auto=update
    spring.datasource.initialization-mode=always
    

    这是我的 data.sql 文件:

    INSERT INTO crypto(departure, details, lowest_price_date, lowest_price_ever, coin_name, url)
    VALUES (null, null, null, 10, 'foooobs', 'http://foo.foo');
    

    问题是,每次重新启动应用程序时,都会添加一个新记录,即使它是上一个会话中的记录。我只想用数据初始化数据库一次,而不想更改它。

    有什么想法吗?

    1 回复  |  直到 6 年前
        1
  •  1
  •   Youcef LAIDANI    6 年前

    ids

    INSERT INTO 
    crypto (id, departure, details, lowest_price_date, lowest_price_ever, coin_name, url)
            ^^
    VALUES (1, null, null, null, 10, 'foooobs', 'http://foo.foo');
            ^
    

    spring.jpa.hibernate.ddl-auto=update


    flyway