获取 Liquibase SQL 服务器错误“找不到对象...因为它不存在或您没有权限”

Getting Liquibase SQL Server error 'Cannot find the object ... because it doesn't exist or you do not have permissions'

我在 Docker 容器中有一个演示 SQL 服务器数据库 运行ning,我正在其上测试 Liquibase。我创建了一个变更日志文件并放入了两个变更集,它们将从特定的 table.

中删除两列

这是我的 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"
        xmlns:pro="http://www.liquibase.org/xml/ns/pro"
        xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.6.xsd
    http://www.liquibase.org/xml/ns/pro http://www.liquibase.org/xml/ns/pro/liquibase-pro-4.6.xsd ">

    <changeSet id="1" author="mdailey">
        <dropColumn tableName="Sales.Invoices" columnName="RunPosition">
        </dropColumn>
    </changeSet>
    <changeSet id="2" author="mdailey">
        <dropColumn tableName="Sales.Invoices" columnName="DeliveryRun">
        </dropColumn>
    </changeSet>
</databaseChangeLog>

当我 运行 liquibase update 时,我不断收到以下错误:

Unexpected error running Liquibase: Cannot find the object "Sales.Invoices" because it does not exist or you do not have permissions. [Failed SQL: (4902) ALTER TABLE [Sales.Invoices] DROP COLUMN RunPosition]

我正在使用 sample database WideWorldImporters Microsoft 提供的。架构是 Sales,因此 table 名称是正确的。我有一个名为 sqladmin 的用户和登录名,登录信息位于 Liquibase 属性文件中。这是属性文件:

# Enter the path for your changelog file.
changeLogFile=changelog/db.changelog-root.xml

# Enter the Target database 'url' information #
liquibase.command.url=jdbc:sqlserver://localhost:1401;database=WideWorldImporters

# Enter the username for your Target database.
liquibase.command.username: sqladmin    

# Enter the password for your Target database.
liquibase.command.password: <StrongPassword>

我将 sqladmin 添加到 db_datawriter 角色,因此它具有足够的权限。当我 运行 SQL 服务器中的 T-SQL 语句作为 'sqladmin' 从相同的 table 中删除相同的列时,它会成功执行。我认为问题出在 Liquibase 但我不知道是什么。

感谢@SMor 的建议,我找到了解决方案。

在变更集中,您不需要在 table 前面添加架构名称,而是需要将其作为单独的属性添加。

<changeSet id="1" author="mdailey">
        <dropColumn schemaName="Sales" tableName="Invoices" columnName="RunPosition">
        </dropColumn>
    </changeSet>