PostgresError: relation "public.artist" does not exist
Hi, I'm new to drizzle. I am getting this error while trying to apply migrations,
69 Replies
I found this, https://github.com/t3-oss/create-t3-turbo/issues/511
which said to remove
s
from table names, which I already tried but no luck.GitHub
bug: drizzle adapter with postgres ends with `error: relation "t3tu...
Provide environment information System: OS: Windows 10 10.0.25300 CPU: (16) x64 AMD Ryzen 7 6800HS with Radeon Graphics Memory: 12.63 GB / 31.26 GB Binaries: Node: 20.5.1 - ~\AppData\Local\Volta\to...
I have also tried creating,
then replacing all
pgTable
to schema.table
, and I get this error,
Can anyone help with this?You are trying to apply a migration to a database that is not in the state the migration script expects
You might have dropped tables or otherwise changed the structure manually?
I have tried deleting the migration directory and DB entirely and start from scratch multiple times still same error.
If you deleted the migration directory, you should generate a new migration. You also have to make sure you drop the __drizzle_migrations table from the database as well
Just so you know, you should not delete those files manually. There is a drop command when you want to start over
I use use docker for
postgresql
and I ran docker system prune -fa
to delete the container, volume and all, and also delete the migrations
directory. So its almost like nothing ever happened..
after this I have to generate the migration again and then run migrate.
Yes, I am aware I am only doing this because ATM its not working.youre creating a schema... but are you also exporting it?
if you dont export it like table defintions, it won't get created, thus you see the error youre getting
What do you mean by exporting?
these are the 2 commands I run,
here is my
migrate.ts
file,
you wrote this line
then tried to add a table to it... you would need
ATM I am not using
pgSchema
I am using pgTable()
But I can try using pgSchema
again with export
.in the last error log you posted that was the issue
Yes, I said I tried that, and that also causes error.
OK,
works..
Why does directly using
pgTable
not work?it does... but you were using a new schema in the second example you posted.. which needed to be created
after every change I made I deleted the migrations directory and docker container hosting postgres DB.
and ran generate and migrate after that..
without seeing your actual code or errors no one can know what mistake you are making
should I share my schema here?
here is a video showing my deleting the db and migration directory and running generate and migrate command after that..
in the video I am not using
pgSchema
but pgTable
directly.can you show album table definition
Artist.id
youre using capital letters
RecordLabel.id
variable name? they need to be lower case too?
ok nm yh i glances without reading.. one sec
how is the volume defined in your docker container, its not a shared volume right>
whats in your drizzle config?
that is global volume no? drizzle-db
it still exists after compose down
I run
docker-compose down -v
, -v
deletes the volume related to container too.
otherwise drizzle would have said about duplicates or something I suppose.no the sql is create if not exists
when it fails can u look in your db see what it has
inside the db?
yeah the migrate fails
I mean the migration hasn't run so how would the db exist?
its got part way
what query do I run inside the psql shell?
ok tell you what.. before doing that.. do aa compose up and the n do a drizzle kit introspect
its probably because url is from a env var..
yeah you owuld need to add dotenv in there.. jsut temp paste it in
right?
no
you mean paste the url in?
yeah just temp for this cmd
one sec
its has 0 records looks like
ok can you show me generated sql from the last migration i nmigrations folder
its huge..
probably has to use some pastebin thing
.sql
file right?ps did you do a compose down -v bthen up again before yopu introspect?
no its running since I posted the video here
then it should have tables in it..... as it breakpoints after each table.. the fks are added at teh end
so ....
in your migrations file
migrations.ts
can you temp paste the same url in there and not use the env
this?
yeah
now run migrate?
yh
same error
ok i need to see sql file then
one sec..
here you go, https://termbin.com/rhr5
i ran it as is, it worked
there is something wrong with yoursetup
hmm.. but I showed you everything.. drizzle config, schema, migrate script, pgsql docker container thing..
is there some version different for some tool here perhaps?
well its just passing the sql to the db
maybe the issue is with the postgres version
if it doesnt havbe enum it would fail i guess
what version of postgres you have?
15 alpine
let me change 13 to 15 then..
updated to 15.. still got same error,
as a test goto one opf the free db sites like supabase etc and jsut paste teh query in, you see there is nothing wrong with it
deleted everything before running generate and migrate this time as well
no I am not saying there is..
just wondering whats wrong with my setup then..
I mean using
pgSchema
it worked ..
something is wrong when I use pgTable
directlyohhh ofc
dont you need to add the init scripts!!!!!
youre using an image thats not setup
so it has no schema
try add an export const newSchema = pgSchema("public")
but.. I have another one of my project using rust, in which I use diesel orm.. I never setup any schema with that..
perhaps they do that automatically and drizzle doesn't
its all i can think of tbh
also .. before I had simple table for user.. no FK or anything.. it worked that time.. I didn't setup any
pgSchema
that time either..then i dont know
im sorry i cant help you
hmm.. its ok I guess.
I'll use
pgSchema
till I figure out what's happening then I guess.