我试图弄清楚如何重构以下sql以正确迁移到Mysql表
CREATE TABLE [LinkedAccountClaims](
[UserAccountID] [uniqueidentifier] NOT NULL,
[ProviderName] [nvarchar](30) NOT NULL,
[ProviderAccountID] [nvarchar](100) NOT NULL,
[Type] [nvarchar](150) NOT NULL,
[Value] [nvarchar](150) NOT NULL,
CONSTRAINT [PK_LinkedAccountClaims] PRIMARY KEY CLUSTERED
(
[UserAccountID] ASC,
[ProviderName] ASC,
[ProviderAccountID] ASC,
[Type] ASC,
[Value] ASC)
CREATE NONCLUSTERED INDEX [IX_UserAccountID] ON [LinkedAccountClaims]
( [UserAccountID] ASC)
ALTER TABLE [LinkedAccountClaims] WITH CHECK ADD CONSTRAINT [FK_LinkedAccountClaims_UserAccounts_UserAccountID] FOREIGN KEY([UserAccountID])
REFERENCES [UserAccounts] ([ID])
ON DELETE CASCADE
到迁移,结构如下
CreateTable(
"LinkedAccountClaims",
c => new
{
UserAccountID = c.String(nullable: false, maxLength: 38, storeType: "char"),
ProviderName = c.String(nullable: false, maxLength: 30, storeType: "nvarchar"),
ProviderAccountID = c.String(nullable: false, maxLength: 100, storeType: "nvarchar"),
Type = c.String(nullable: false, maxLength: 150, storeType: "nvarchar"),
Value = c.String(nullable: false, maxLength: 150, storeType: "nvarchar"),
})
.PrimaryKey(t => t.UserAccountID)
.PrimaryKey(t => t.ProviderName)
.PrimaryKey(t => t.ProviderAccountID)
.PrimaryKey(t => t.Type)
.PrimaryKey(t => t.Value)
.Index(t => t.UserAccountID);
我不确定我是否在迁移中正确地进行了主键聚类,而且我不确定如何处理外键。
更新 这是正确地聚类主键并添加你使用代码的foregin键
.ForeignKey("UserAccounts", t => t.UserAccountID, cascadeDelete: true)
答案 0 :(得分:0)
MySQL的语法和支持略有不同,其他人试试这个。不要在表中使用多个主键
CREATE TABLE LinkedAccountClaims(
UserAccountID int unique NOT NULL ,
ProviderName varchar(30) NOT NULL,
ProviderAccountID varchar(100) NOT NULL,
Type varchar(150) NOT NULL,
Value varchar(150) NOT NULL,
primary key (UserAccountID)
);
CREATE INDEX IX_UserAccountID ON LinkedAccountClaims
(UserAccountID);
ALTER TABLE LinkedAccountClaims ADD CONSTRAINT FK_LinkedAccountClaims_UserAccounts_UserAccountID FOREIGN KEY(UserAccountID)
REFERENCES UserAccounts(ID)
ON DELETE CASCADE;
答案 1 :(得分:0)
您是否考虑过使用Pentaho数据集成进行转换?