我正在尝试创建一个基于schema.sql的prisma模型
看看这个:
model market_history {
id Int @id @default(autoincrement())
player_id Int
sale Int @default(0) @db.TinyInt
itemtype Int @db.UnsignedSmallInt
amount Int @db.UnsignedSmallInt
price BigInt @default(0) @db.UnsignedBigInt
expires_at BigInt @db.UnsignedBigInt
inserted BigInt @db.UnsignedBigInt
state Int @db.UnsignedTinyInt
f_player_id players @relation(fields: [player_id], references: [id])
}结果是:
CREATE TABLE `market_history` (
`id` INTEGER NOT NULL AUTO_INCREMENT,
`player_id` INTEGER NOT NULL,
`sale` TINYINT NOT NULL DEFAULT 0,
`itemtype` SMALLINT UNSIGNED NOT NULL,
`amount` SMALLINT UNSIGNED NOT NULL,
`price` BIGINT UNSIGNED NOT NULL DEFAULT 0,
`expires_at` BIGINT UNSIGNED NOT NULL,
`inserted` BIGINT UNSIGNED NOT NULL,
`state` TINYINT UNSIGNED NOT NULL,
PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;但“原始”代码是:
CREATE TABLE `market_history` (
`id` int unsigned NOT NULL AUTO_INCREMENT,
`player_id` int NOT NULL,
`sale` tinyint(1) NOT NULL DEFAULT '0',
`itemtype` int unsigned NOT NULL,
`amount` smallint unsigned NOT NULL,
`price` int unsigned NOT NULL DEFAULT '0',
`expires_at` bigint unsigned NOT NULL,
`inserted` bigint unsigned NOT NULL,
`state` tinyint unsigned NOT NULL,
PRIMARY KEY (`id`),
KEY `player_id` (`player_id`,`sale`),
CONSTRAINT `market_history_ibfk_1` FOREIGN KEY (`player_id`) REFERENCES `players` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=1300 DEFAULT CHARSET=latin1;看那个键player_id (player_id,sale)
我想知道关于普里斯玛的关键问题是否可能
发布于 2022-06-05 09:33:10
我不熟悉KEY关键字,但根据这一反应,它与MySQL中的索引相同。因此,您可以通过在多域(又名复合)指数模型上定义一个market_history来获得相同的行为:
model market_history {
id Int @id @default(autoincrement())
player_id Int
sale Int @default(0) @db.TinyInt
itemtype Int @db.UnsignedSmallInt
amount Int @db.UnsignedSmallInt
price BigInt @default(0) @db.UnsignedBigInt
expires_at BigInt @db.UnsignedBigInt
inserted BigInt @db.UnsignedBigInt
state Int @db.UnsignedTinyInt
f_player_id players @relation(fields: [player_id], references: [id])
@@index([player_id, sale])
}https://stackoverflow.com/questions/72501507
复制相似问题