MySQL UUID as PK

I am unable to get a PK setup which has a default UUID value. I have
logID: varchar('logID', { length: 48 }).default(sql`'UUID()'`).primaryKey(),
logID: varchar('logID', { length: 48 }).default(sql`'UUID()'`).primaryKey(),
in my table schema But it creates a migration query that literally adds the literal string 'UUID()' in the field
CREATE TABLE `feedLogs` (
`logID` varchar(48) NOT NULL DEFAULT 'UUID()',
`feedType` varchar(10),
CONSTRAINT `feedLogs_logID` PRIMARY KEY(`logID`)
);
CREATE TABLE `feedLogs` (
`logID` varchar(48) NOT NULL DEFAULT 'UUID()',
`feedType` varchar(10),
CONSTRAINT `feedLogs_logID` PRIMARY KEY(`logID`)
);
but running this in MySQL directly, the table is created with a PK that does default to an actual UUID string value
mr_pablo
mr_pablo240d ago
Oh, and I'm using Drizzle ORM 0.28.2 and Kit 0.19.13
mr_pablo
mr_pablo239d ago
I did
logID: varchar('logID', { length: 48 }).default(sql`UUID()`).primaryKey(),
logID: varchar('logID', { length: 48 }).default(sql`UUID()`).primaryKey(),
and
logID: varchar('logID', { length: 48 }).default(sql`'UUID()'`).primaryKey(),
logID: varchar('logID', { length: 48 }).default(sql`'UUID()'`).primaryKey(),
These don't work. MySQL has a UUID() method, but as mentioned, right now, despite using the magic sql operator, the literal string value of UUID() is being inserted, not an actual UUID
Angelelz
Angelelz239d ago
You need to check the version of Mysql you are using. It may or may not support the use of non deterministic default values
Angelelz
Angelelz239d ago
Stack Overflow
MySQL set default id UUID
I'm trying to create tables in a database that has an id field that will populate the id with an UUID by default. I tried something like: CREATE TABLE FOO ( id CHAR(36) PRIMARY KEY DEFAULT uuid...
Angelelz
Angelelz239d ago
Maybe you can try it this way
logID: varchar('logID', { length: 48 }).default(sql`('UUID()')`).primaryKey(),
logID: varchar('logID', { length: 48 }).default(sql`('UUID()')`).primaryKey(),
Want results from more Discord servers?
Add your server
More Posts
totalCount from relational queryis it somehow possible to get the total count of a relational query? Core queries aren't possible hCannot read properties of undefined (reading \'columns\')I tired using relational queries ` const bookmarkdb = drizzle(pool, { schema }); coDoes Drizzle support Microsoft SQL Server?Does Drizzle support Microsoft SQL Server ?Findfirst and Findmany configHello I am new to using drizzle and can't seem to make the findFirst and findMany work. I am using pTrouble running JEST testing in Hono for Cloudfare WorkersSo, I have an API setup in Hono with cloudfare workers and I setup the JEST tests but they don't seeHelp migrating a nested Prisma updateBeen trying to set this up without going through the raw sql route for some time but cant seem to wrWhich typescript type should I use for select?Hi, this question might be confusing. Let me explain the problem, I'm building a common function forpush:sqlite creating weird tablesWhen I run push:sqlite, tables like `__old_push_categories` are created and are automatically refrenUsing a placeholder with an inArrayI'm porting a query to a prepared statement, in the query I used to do something like: ``` .where(iDB insertion - Date field (mode: string) is using default value instead of passed valueTrying to insert an Order object which has a "pickupTime" Date field to db, but upon insertion the cBest practice on connections for PostgreSQLI got the following error; `remaining connection slots are reserved for non-replication superuser cMinimum value for Postgres bigserialI want my id tables to use bigserial, but i want the first row to be inserted with the value 222222.Prepend raw fields with table/subquery name in rendered SQLCurrently, it doesn't seem like raw fields in a select statement hold any information on the table/sIs there a faster way todo this?```typescript await db.transaction(async (tx) => { for (let i = 0; i < data.length; i++) {