mysql Liquibase添加默认值

9w11ddsr  于 12个月前  发布在  Mysql
关注(0)|答案(4)|浏览(82)

我创建了一个名为person的表,并使用liquibase变更集添加了一列“phone_number”。但现在我想为它添加一个默认值。但它没有工作,到目前为止,我已经尝试了:

<addDefaultValue columnName="phone_number"
                 defaultValue="+923331234567"
                 tableName="person"/>

<changeSet author="haseeb" id="20160413123500">
    <update tableName="person">
        <column name="phone_number" type="varchar(255)" defaultValue="+923331234567"/>
    </update>
</changeSet>

<changeSet author="haseeb" id="20160413123501">
    <update tableName="person">
        <column name="phone_number" type="varchar(255)" value="+923331234567"/>
</update>

有人能指出我哪里做错了吗?添加默认值是否会为以前添加的行添加值?

kx1ctssn

kx1ctssn1#

试试这个

<addDefaultValue columnName="phone_number"
             defaultValue="+923331234567"
             tableName="person" columnDataType="varchar(255)"/>
0lvr5msh

0lvr5msh2#

试试这个:

<changeSet author="haseeb" id="20160413123501">
    <modifyDataType
        columnName="phone_number"
        newDataType="varchar(255)"
        defaultValue="+923331234567"
        tableName="person"/>
    <comment>Change default value</comment>
</changeSet>
zf2sa74q

zf2sa74q3#

expression是这样的:

- addDefaultValue:
    tableName: RT_STAGE
    columnName: CREATED_DATE
    defaultValueComputed: now()

对于boolean

- addDefaultValue:
    tableName: RT_STAGE
    columnName: FINAL
    defaultValueBoolean: false
biswetbf

biswetbf4#

YAML脚本在liquibase中创建表,默认值为string/varchar,integer和timestamp -

databaseChangeLog:
  - changeSet:
    id: liq_003
    author: Pravind
    changes:
      - sql:
        dbms: postgresql
        sql: DROP TABLE IF EXISTS test.fx_users CASCADE
      - createTable:
        tableName: fx_users
        remarks: "System authentication table"
        schemaName: test
        columns:             
          - column:
              name: username
              type: varchar(50)
              remarks: "user name, will be used for authentication"
              constraints:
                nullable: false
                unique: true
          - column:
              name: password
              type: varchar(50)
              remarks: "user password"
              constraints:
                nullable: false
          - column:
              name: email
              type: varchar(50)
              remarks: "User Email Id"
              constraints:
                nullable: false              
          - column:
              name: version
              type: int
              defaultValue: "0"
              remarks: "entity current version"
              constraints:
                nullable: true
          - column:
              name: created_on
              type: timestamp
              remarks: "Entity created time"
              defaultValueComputed: "now()"
              constraints:
                nullable: true
          - column:
              name: created_by
              type: varchar(50)
              remarks: "Name of the user who created this entity"
              defaultValue: "system"
              constraints:
                nullable: true

相关问题