-
I got this error when running
Here is the tables & relations import { relations } from `drizzle-orm`;
import { integer, pgTable, primaryKey, text, timestamp, jsonb, real } from `drizzle-orm/pg-core`;
import { ulid } from `ulidx`;
export const vendor = pgTable(`vendors`, {
id: text(`id`).primaryKey().$defaultFn(() => ulid()),
created_at: timestamp(`created_at`).notNull().defaultNow(),
updated_at: timestamp(`updated_at`).notNull().$onUpdate(() => new Date()),
name: text(`name`).unique().notNull(),
country: text(`country`),
avatar: text(`avatar`),
sale_pages: jsonb(`sale_pages`),
slug: text(`slug`).notNull(),
views: integer(`views`).default(0),
type: integer(`type`).notNull()
});
export const model = pgTable(`models`, {
id: text(`id`).primaryKey().$defaultFn(() => ulid()),
created_at: timestamp(`created_at`).notNull().defaultNow(),
updated_at: timestamp(`updated_at`).notNull().$onUpdate(() => new Date()),
name: text(`name`).unique().notNull(),
readable_name: text(`readable_name`),
related_names: text(`related_names`),
country: text(`country`),
slug: text(`slug`).notNull(),
featured: integer(`featured`).default(0),
circle_avatar: text(`circle_avatar`).notNull(),
vertical_avatar: text(`vertical_avatar`),
dob: text(`dob`),
measurements: text(`measurements`),
rating: real(`rating`).notNull(),
views: integer(`views`).default(0),
})
export const vendor2Model = pgTable(`vendors_2_models`, {
vendor_id: text(`vendor_id`).notNull().references(() => vendor.id),
model_id: text(`model_id`).notNull().references(() => vendor.id),
}, (t) => ({ pk: primaryKey({ columns: [ t.vendor_id, t.model_id ] }), })); export const vendorRelations = relations(vendor, ({ many }) => ({
models: many(model),
}))
export const modelRelations = relations(model, ({ many }) => ({
vendors: many(vendor),
}))
export const vendor2ModelRelations = relations(vendor2Model, ({ one }) => ({
vendor: one(vendor, {
fields: [ vendor2Model.vendor_id ],
references: [ vendor.id ],
}),
model: one(model, {
fields: [ vendor2Model.model_id ],
references: [ model.id ],
}),
})); My drizzle.config.js import { defineConfig } from "drizzle-kit";
export default defineConfig({
dialect: "postgresql",
dbCredentials: {
url: `postgres://postgres:1@0.0.0.0:5432/postgres`,
},
schema: "./db/schemas.js",
out: "./db/migrations",
}); My package.json
The .sql file after run
|
Beta Was this translation helpful? Give feedback.
Answered by
jdkcoder
Jun 15, 2024
Replies: 1 comment
-
Adding id: text(`id`).primaryKey().$defaultFn(() => ulid()).unique() |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
jdkcoder
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Adding
.unique()
after$defaultFn()
solved my problem. I forgot that :'(