在 SQL Server 上使用 Liquibase 时出错
我正在试验 Liquibase,试图让它将一个数据库复制到另一个数据库。不幸的是,我不断收到此错误:
不允许从数据类型 varchar 到 varbinary 的隐式转换。 使用 CONVERT 函数来运行它 查询。
它生成的 SQL 在这里:
CREATE TABLE [dbo].[Attachment] (
[Applicantid] uniqueidentifier NOT NULL,
[Attachmentid] uniqueidentifier CONSTRAINT DF_Attachment_Attachmentid DEFAULT '(newid())' NOT NULL,
[AttachmentType] INT CONSTRAINT DF_Attachment_AttachmentType DEFAULT 0 NOT NULL,
[FileAttachment] image NOT NULL,
[FileName] ntext NOT NULL,
[FileType] nvarchar(125) NOT NULL,
[Filesize] INT NOT NULL,
[CCN] varbinary(8) CONSTRAINT DF_Attachment_CCN DEFAULT '0' NOT NULL,
[CreateDate] DATETIME CONSTRAINT DF_Attachment_CreateDate DEFAULT (getdate()) NOT NULL,
[LastUpdate] DATETIME CONSTRAINT DF_Attachment_LastUpdate DEFAULT (getdate()) NOT NULL,
CONSTRAINT [PK_Attachment] PRIMARY KEY (Attachmentid)
):
I'm experimenting with Liquibase, trying to get it to copy one database to another. Unfortunately, I keep getting this error:
Implicit conversion from data type varchar to varbinary is not allowed.
Use the CONVERT function to run this
query.
The SQL it's generating is here:
CREATE TABLE [dbo].[Attachment] (
[Applicantid] uniqueidentifier NOT NULL,
[Attachmentid] uniqueidentifier CONSTRAINT DF_Attachment_Attachmentid DEFAULT '(newid())' NOT NULL,
[AttachmentType] INT CONSTRAINT DF_Attachment_AttachmentType DEFAULT 0 NOT NULL,
[FileAttachment] image NOT NULL,
[FileName] ntext NOT NULL,
[FileType] nvarchar(125) NOT NULL,
[Filesize] INT NOT NULL,
[CCN] varbinary(8) CONSTRAINT DF_Attachment_CCN DEFAULT '0' NOT NULL,
[CreateDate] DATETIME CONSTRAINT DF_Attachment_CreateDate DEFAULT (getdate()) NOT NULL,
[LastUpdate] DATETIME CONSTRAINT DF_Attachment_LastUpdate DEFAULT (getdate()) NOT NULL,
CONSTRAINT [PK_Attachment] PRIMARY KEY (Attachmentid)
):
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
那些 liquibase 项目人员需要了解有关 SQL Server 最新版本(2005 及更高版本)的一些知识:
NTEXT
早已被弃用 - 使用NVARCHAR(MAX)
代替IMAGE
也早已被弃用 - 请使用VARBINARY(MAX)
代替(但是,如果您使用的是 SQL Server 2000 或更早版本,这些数据类型就可以了)。
另外:仅根据该表定义,无法找出出现此错误的原因。这是您的原始(源)表,还是 Liquibase 生成的目标表?如果是这样:您有机会看到/跟踪/检查用于将数据从旧表迁移到新表的 SQL 语句吗?
也许那里有一个
varchar
列,您尝试将其隐式转换为varbinary
...Those liquibase project guys need to learn a few things about more recent versions of SQL Server - 2005 and up:
NTEXT
is long been deprecated - useNVARCHAR(MAX)
insteadIMAGE
is long been deprecated, too - useVARBINARY(MAX)
instead(those datatypes would be OK if you're dealing with SQL Server 2000 or earlier, however).
Plus: just from that table definition, there's no way to be able to figure out why you get this error. Is this your original (source) table, or is this what Liquibase generates as a target table?? If so: any chance you can see / trace / inspect the SQL statements used to migrate the data from the old to the new table??
Maybe there's a
varchar
column there that you try to convert tovarbinary
implicitly...