ppppp
ppppp
DTDrizzle Team
Created by ppppp on 9/6/2024 in #help
column "foo" referenced in foreign key constraint does not exist
table story:
import { relations } from "drizzle-orm";
import {
type PgColumn,
date,
index,
integer,
pgTable,
serial,
timestamp,
unique,
varchar,
} from "drizzle-orm/pg-core";
import { person } from "./person";

export const story = pgTable(
"story",
{
id: serial("id").primaryKey(),
personId: integer("person_id")
.notNull()
.references((): PgColumn => person.id),
date: date("date").notNull(),
content: varchar("content", { length: 255 }).notNull(),
createdAt: timestamp("created_at", { mode: "string" })
.notNull()
.defaultNow(),
updatedAt: timestamp("updated_at", { mode: "string" })
.notNull()
.defaultNow(),
},
(t) => ({
PersonStoryDateUnq: unique("person_story_date").on(t.date, t.personId),
personIdx: index("person_idx").using("hash", t.personId.asc()),
}),
);

export const storyRelations = relations(story, ({ one }) => ({
person: one(person, {
fields: [story.personId],
references: [person.id],
relationName: "person-story",
}),
}));

export type SelectStory = typeof story.$inferSelect;
export type InsertStory = typeof story.$inferInsert;
import { relations } from "drizzle-orm";
import {
type PgColumn,
date,
index,
integer,
pgTable,
serial,
timestamp,
unique,
varchar,
} from "drizzle-orm/pg-core";
import { person } from "./person";

export const story = pgTable(
"story",
{
id: serial("id").primaryKey(),
personId: integer("person_id")
.notNull()
.references((): PgColumn => person.id),
date: date("date").notNull(),
content: varchar("content", { length: 255 }).notNull(),
createdAt: timestamp("created_at", { mode: "string" })
.notNull()
.defaultNow(),
updatedAt: timestamp("updated_at", { mode: "string" })
.notNull()
.defaultNow(),
},
(t) => ({
PersonStoryDateUnq: unique("person_story_date").on(t.date, t.personId),
personIdx: index("person_idx").using("hash", t.personId.asc()),
}),
);

export const storyRelations = relations(story, ({ one }) => ({
person: one(person, {
fields: [story.personId],
references: [person.id],
relationName: "person-story",
}),
}));

export type SelectStory = typeof story.$inferSelect;
export type InsertStory = typeof story.$inferInsert;
3 replies
DTDrizzle Team
Created by ppppp on 9/6/2024 in #help
column "foo" referenced in foreign key constraint does not exist
table person:
import { relations } from "drizzle-orm";
import { date, pgTable, serial, timestamp, varchar } from "drizzle-orm/pg-core";
import { story } from "./story";

export const person = pgTable("person", {
id: serial("id").primaryKey(),
email: varchar("email", { length: 255 }).notNull(),
password: varchar("password", { length: 255 }).notNull(),
fullname: varchar("fullname", { length: 255 }).notNull(),
birthDate: date("birth_date"),
createdAt: timestamp("created_at", { mode: "string" }).notNull().defaultNow(),
updatedAt: timestamp("updated_at", { mode: "string" }).notNull().defaultNow(),
});

export const personRelations = relations(person, ({ many }) => ({
story: many(story, { relationName: "person-story" }),
}));

export type SelectPerson = typeof person.$inferSelect;
export type InsertPerson = typeof person.$inferInsert;
import { relations } from "drizzle-orm";
import { date, pgTable, serial, timestamp, varchar } from "drizzle-orm/pg-core";
import { story } from "./story";

export const person = pgTable("person", {
id: serial("id").primaryKey(),
email: varchar("email", { length: 255 }).notNull(),
password: varchar("password", { length: 255 }).notNull(),
fullname: varchar("fullname", { length: 255 }).notNull(),
birthDate: date("birth_date"),
createdAt: timestamp("created_at", { mode: "string" }).notNull().defaultNow(),
updatedAt: timestamp("updated_at", { mode: "string" }).notNull().defaultNow(),
});

export const personRelations = relations(person, ({ many }) => ({
story: many(story, { relationName: "person-story" }),
}));

export type SelectPerson = typeof person.$inferSelect;
export type InsertPerson = typeof person.$inferInsert;
3 replies
DTDrizzle Team
Created by ppppp on 8/30/2024 in #help
Unique constraint typescript error
sorry for the late response, i don't use discord that much. there is an eslint rule where you can restrict specific import called no-restricted-imports.
{
"rules": {
"no-restricted-imports": [
"error",
{ "paths": ["drizzle-orm/mysql-core", "drizzle-orm/sqlite-core"] }
]
}
}
{
"rules": {
"no-restricted-imports": [
"error",
{ "paths": ["drizzle-orm/mysql-core", "drizzle-orm/sqlite-core"] }
]
}
}
7 replies
DTDrizzle Team
Created by ppppp on 8/30/2024 in #help
Unique constraint typescript error
Thank youuu 😘 To avoid this mistake again i just set the linter rule where i get error when i import from drizzle-orm/mysql-core and drizzle-orm/sqlite-core
7 replies
DTDrizzle Team
Created by ppppp on 8/30/2024 in #help
Unique constraint typescript error
No description
7 replies