我正在尝试在spring应用程序中创建我的第一个liquibase更改日志。我用maven执行liquibase,但它不起作用。
<?xml version="1.0" encoding="utf-8"?>
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.1.xsd">
<changeSet id="1" author="tobias">
<createTable tableName="Entwickler">
<column name="id" type="int" autoIncrement="true">
<constraints primaryKey="true" nullable="false"/>
</column>
<column name="name" type="varchar(50)"/>
<column name="webseite" type="varchar(50)"/>
<column name="gruendungsdatum" type="BIGINT"/>
</createTable>
<createTable tableName="Publisher">
<column name="id" type="int" autoIncrement="true">
<constraints primaryKey="true" nullable="false"/>
</column>
<column name="name" type="varchar(50)"/>
<column name="webseite" type="varchar(50)"/>
<column name="gruendungsdatum" type="BIGINT"/>
</createTable>
<createTable tableName="Spiel">
<column name="id" type="int" autoIncrement="true">
<constraints primaryKey="true" nullable="false"/>
</column>
<column name="name" type="varchar(50)"/>
<column name="publisher_id" type="int">
<constraints nullable="false"
foreignKeyName="fk_publisher"
references="Publisher(id)"/>
</column>
</createTable>
<createTable tableName="Bilder">
<column name="id" type="int" autoIncrement="true">
<constraints primaryKey="true" nullable="false"/>
</column>
<column name="name" type="varchar(50)"/>
<column name="picture_kind" type="varchar(50)"/>
<column name="game_id" type="int">
<constraints nullable="false"
foreignKeyName="fk_game"
references="Spiel(id)"/>
</column>
</createTable>
<createTable tableName="Spiel_Entwickler">
<column name="id" type="int" autoIncrement="true">
<constraints primaryKey="true" nullable="false"/>
</column>
<column name="entwickler_id" type="int">
<constraints nullable="false"
foreignKeyName="fk_Entwickler"
references="Entwickler(id)"/>
</column>
<column name="game_id" type="int">
<constraints nullable="false"
foreignKeyName="fk_Game"
references="Spiel(id)"/>
</column>
</createTable>
<createTable tableName="Language">
<column name="id" type="int" autoIncrement="true">
<constraints primaryKey="true" nullable="false"/>
</column>
<column name="Language" type="varchar(50)"/>
</createTable>
<createTable tableName="plattform">
<column name="id" type="int" autoIncrement="true">
<constraints primaryKey="true" nullable="false"/>
</column>
<column name="plattform" type="varchar(50)"/>
</createTable>
<createTable tableName="Redaktion">
<column name="id" type="int" autoIncrement="true">
<constraints primaryKey="true" nullable="false"/>
</column>
<column name="Redaktion" type="varchar(50)"/>
</createTable>
<createTable tableName="Language_Spiel">
<column name="id" type="int" autoIncrement="true">
<constraints primaryKey="true" nullable="false"/>
</column>
<column name="name" type="varchar(50)"/>
<column name="spiel_id" type="int">
<constraints nullable="false"
foreignKeyName="fk_spiel"
references="Spiel(id)"/>
</column>
<column name="language_id" type="int">
<constraints nullable="false"
foreignKeyName="fk_language"
references="Language(id)"/>
</column>
<column name="Youtube" type="varchar(50)"/>
<column name="Beschreibung" type="varchar(50)"/>
<column name="Altersfreigabe" type="int"/>
</createTable>
<createTable tableName="spiel_plattform">
<column name="id" type="int" autoIncrement="true">
<constraints primaryKey="true" nullable="false"/>
</column>
<column name="name" type="varchar(50)"/>
<column name="spiel_id" type="int">
<constraints nullable="false"
foreignKeyName="fk_spiel"
references="Language_Spiel(id)"/>
</column>
<column name="plattform_id" type="int">
<constraints nullable="false"
foreignKeyName="fk_plattform"
references="plattform(id)"/>
</column>
<column name="releasedate" type="bigint"/>
<column name="releasedate_kind" type="varchar(50)"/>
<column name="shop" type="varchar(50)"/>
</createTable>
<createTable tableName="Rating">
<column name="id" type="int" autoIncrement="true">
<constraints primaryKey="true" nullable="false"/>
</column>
<column name="redaktion_id" type="int">
<constraints nullable="false"
foreignKeyName="fk_Rating"
references="Redaktion(id)"/>
</column>
<column name="plattform_id" type="int">
<constraints nullable="false"
foreignKeyName="fk_plattform"
references="spiel_plattform(id)"/>
</column>
<column name="rating" type="bigint"/>
</createTable>
<createTable tableName="Genre">
<column name="id" type="int" autoIncrement="true">
<constraints primaryKey="true" nullable="false"/>
</column>
<column name="genre" type="bigint"/>
</createTable>
<createTable tableName="Rating">
<column name="id" type="int" autoIncrement="true">
<constraints primaryKey="true" nullable="false"/>
</column>
<column name="game_id" type="int">
<constraints nullable="false"
foreignKeyName="fk_Game"
references="Language_Spiel(id)"/>
</column>
<column name="genre_id" type="int">
<constraints nullable="false"
foreignKeyName="fk_genre"
references="Genre(id)"/>
</column>
<column name="rating" type="bigint"/>
</createTable>
</changeSet>
</databaseChangeLog>
我用maven执行liquibase。 mvn liquibase:update。
执行后,我得到错误,我需要在模式位置的标题中包含偶数uris:
C:\Users\Tobi\IdeaProjects\games>mvn liquibase:update
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building games 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- liquibase-maven-plugin:3.4.2:update (default-cli) @ games ---
[INFO] ------------------------------------------------------------------------
[INFO] Parsing Liquibase Properties File
[INFO] File: liquibase/liquibase.properties
[INFO] ------------------------------------------------------------------------
[INFO] Executing on Database: jdbc:mysql://localhost:3306/games
INFO 19.05.18 14:44: liquibase: Successfully acquired change log lock
WARNING 19.05.18 14:44: liquibase: SchemaLocation: schemaLocation-Wert = 'http://www.liquibase.org/xml/ns/dbchangelog http://www
.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.0.xsd http://www.liquibase.org/xml/ns/dbchangelog-ext http://www.liquiba
se.org/xml/ns/dbchangelog/dbchangelog-ext.xsd http://www.liquibase.org/xml/ns/dbchangelog-ext ' muss eine gerade Anzahl an URIs
haben.
INFO 19.05.18 14:44: liquibase: Successfully released change log lock
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.568 s
[INFO] Finished at: 2018-05-19T14:44:16+02:00
[INFO] Final Memory: 13M/200M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.liquibase:liquibase-maven-plugin:3.4.2:update (default-cli) on project games: Error setting u
p or running Liquibase: liquibase.exception.SetupException: Error parsing line 7 column 52 of liquibase/changelogs/Gameinterface
-changelog-1.xml: SchemaLocation: schemaLocation-Wert = 'http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xm
l/ns/dbchangelog/dbchangelog-3.0.xsd http://www.liquibase.org/xml/ns/dbchangelog-ext http://www.liquibase.org/xml/ns/dbc
hangelog/dbchangelog-ext.xsd http://www.liquibase.org/xml/ns/dbchangelog-ext ' muss eine gerade Anzahl an URIs haben. -> [Help 1
]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
我的问题是堆栈跟踪说我在7号位置52的架构位置需要偶数个uris。但是我的标题行不在第7行但在第4行。我在intelliJ终端中执行了liquibase并且在cmd。
答案 0 :(得分:0)
在maven日志中,你有:
SchemaLocation: schemaLocation-Wert = 'http://www.liquibase.org/xml/ns/dbchangelog
http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.0.xsd
http://www.liquibase.org/xml/ns/dbchangelog-ext
http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd
http://www.liquibase.org/xml/ns/dbchangelog-ext' muss eine gerade Anzahl an URIs haben.
所以尝试使用:
<databaseChangeLog
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.0.xsd
http://www.liquibase.org/xml/ns/dbchangelog-ext http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd">
您使用的是什么版本的liquibase
?
此外,您的changeSet应该有preconditions
,因此当您使用现有数据库执行它们时,它们不会失败。
因此:
<changeSet id="1" author="tobias">
<preConditions onFail="MARK_RAN">
<not>
<tableExists tableName="Entwickler"/>
</not>
</preConditions>
<createTable tableName="Entwickler">
<column name="id" type="int" autoIncrement="true">
<constraints primaryKey="true" nullable="false"/>
</column>
<column name="name" type="varchar(50)"/>
<column name="webseite" type="varchar(50)"/>
<column name="gruendungsdatum" type="BIGINT"/>
</createTable>
</changeSet>
此外,表名应以小写字母开头。
尝试制作你的changeSets
原子。一个changeSet
- 一个数据库更改。不要将所有表的创建放在一个changeSet
中。