basir / next-15-admin-dashboard

https://next-15-admin-dashboard.vercel.app
22 stars 11 forks source link

Failed to seed database #1

Open smartdriver321 opened 4 months ago

smartdriver321 commented 4 months ago

npx tsx ./db/seed.ts VercelPostgresError: VercelPostgresError - 'missing_connection_string': You did not supply a 'connectionString' and no 'POSTGRES_URL' env var was found. at createPool (C:\Users\user\Documents\dashboard-apps\dash-admin15\node_modules.pnpm\@vercel+postgres@0.9.0\node_modules\@vercel\postgres\src\create-pool.ts:86:11) at Object.get (C:\Users\user\Documents\dashboard-apps\dash-admin15\node_modules.pnpm\@vercel+postgres@0.9.0\node_modules\@vercel\postgres\src\index.ts:23:16) at VercelPgPreparedQuery.execute (C:\Users\user\Documents\dashboard-apps\dash-admin15\nodemodules.pnpm\drizzle-orm@0.32.0@neondatabase+serverless@0.9.4@types+pg@8.11.6@types+react@18.3.3_@verce_r3smpz6pan4xhwuh675nfk5pbe\node_modules\src\vercel-postgres\session.ts:57:18) at QueryPromise.execute (C:\Users\user\Documents\dashboard-apps\dash-admin15\nodemodules.pnpm\drizzle-orm@0.32.0@neondatabase+serverless@0.9.4@types+pg@8.11.6@types+react@18.3.3_@verce_r3smpz6pan4xhwuh675nfk5pbe\node_modules\src\pg-core\db.ts:604:19) at QueryPromise.then (C:\Users\user\Documents\dashboard-apps\dash-admin15\nodemodules.pnpm\drizzle-orm@0.32.0@neondatabase+serverless@0.9.4@types+pg@8.11.6@types+react@18.3.3_@verce_r3smpz6pan4xhwuh675nfk5pbe\node_modules\src\query-promise.ts:31:15) { code: 'missing_connection_string'
} C:\Users\user\Documents\dashboard-apps\dash-admin15\db\seed.ts:24 throw new Error('Failed to seed database') ^

Error: Failed to seed database
at main (C:\Users\user\Documents\dashboard-apps\dash-admin15\db\seed.ts:24:9)

Node.js v21.5.0

cryptodude-go commented 4 months ago

i also get the similar error PS C:\Users\User\dash-admin> npx drizzle-kit push drizzle-kit: v0.23.0 drizzle-orm: v0.32.0

No config path provided, using default path Reading config file 'C:\Users\User\dash-admin\drizzle.config.ts' Using '@vercel/postgres' driver for database querying Warning '@vercel/postgres' can only connect to remote Neon/Vercel Postgres/Supabase instances through a websocket [✓] Pulling schema from database... error: function uuid_generate_v4() does not exist at C:\Users\User\dash-admin\node_modules.pnpm\drizzle-kit@0.23.0\node_modules\drizzle-kit\bin.cjs:87414:23 at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async Object.query (C:\Users\User\dash-admin\node_modules.pnpm\drizzle-kit@0.23.0\node_modules\drizzle-kit\bin.cjs:121475:26) at async pgPush (C:\Users\User\dash-admin\node_modules.pnpm\drizzle-kit@0.23.0\node_modules\drizzle-kit\bin.cjs:124361:13) at async _Command. (C:\Users\User\dash-admin\node_modules.pnpm\drizzle-kit@0.23.0\node_modules\drizzle-kit\bin.cjs:131618:7) { length: 211, severity: 'ERROR', code: '42883', detail: undefined, hint: 'No function matches the given name and argument types. You might need to add explicit type casts.', position: '73', internalQuery: undefined, where: undefined, schema: undefined, table: undefined, column: undefined, dataType: undefined, constraint: undefined, file: 'parse_func.c', line: '629', routine: 'ParseFuncOrColumn' }

and on next command again PS C:\Users\User\dash-admin> npx tsx ./db/seed.ts Need to install the following packages: tsx@4.16.2 Ok to proceed? (y) y error: relation "revenue" does not exist at C:\Users\User\dash-admin\node_modules.pnpm\@neondatabase+serverless@0.9.4\node_modules\@neondatabase\serverless\index.js:1345:74 at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at (C:\Users\User\dash-admin\db\seed.ts:10:7) at VercelPgSession.transaction (C:\Users\User\dash-admin\nodemodules.pnpm\drizzle-orm@0.32.0@neondatabase+serverless@0.9.4@types+pg@8.11.6@types+react@18.3.3_@verce_r3smpz6pan4xhwuh675nfk5pbe\node_modules\src\vercel-postgres\session.ts:155:19) at main (C:\Users\User\dash-admin\db\seed.ts:9:5) { length: 106, severity: 'ERROR', code: '42P01', detail: undefined, hint: undefined, position: '13', internalPosition: undefined, internalQuery: undefined, where: undefined, schema: undefined, table: undefined, column: undefined, dataType: undefined, constraint: undefined, file: 'parse_relation.c', line: '1449', } C:\Users\User\dash-admin\db\seed.ts:25 throw new Error('Failed to seed database') ^

Error: Failed to seed database at main (C:\Users\User\dash-admin\db\seed.ts:25:11) at process.processTicksAndRejections (node:internal/process/task_queues:95:5)

Node.js v21.5.0

check it out.

basir commented 4 months ago

@smartdriver321 the error is self-explanatory. do you have .env.local in the root folder of the project which contains POSTGRES_URL? I updated the README.md here: https://github.com/basir/next-15-admin-dashboard?tab=readme-ov-file#run-locally

basir commented 4 months ago

@cryptodude-go The error "error: function uuid_generate_v4() does not exist" typically occurs when you're trying to use the uuid_generate_v4() function in a database system that doesn't have it built-in by default. Here's how to fix it:

  1. Check Database Compatibility:

PostgreSQL: The uuid_generate_v4() function is available in PostgreSQL by default. No additional setup is needed.

Other Databases: If you're using a different database system, it might not have a built-in uuid_generate_v4() function. You'll need to check your database's documentation for alternative methods of generating UUIDs. Some databases might offer similar functionality with different function names.

  1. Enable Extension (PostgreSQL):

If you're using PostgreSQL and the function isn't working even though it should be available, there might be a schema search path issue. You can try enabling the uuid-ossp extension explicitly: SQL CREATE EXTENSION IF NOT EXISTS "uuid-ossp"; Use code with caution.

  1. Alternative Methods:

If your database doesn't support uuid_generate_v4() or enabling the extension isn't an option, you can explore alternative methods for generating UUIDs:

Client-side generation: You can generate UUIDs in your application code before sending them to the database. There are libraries available for most programming languages that can handle UUID generation. Database-specific functions: Some databases offer alternative functions for generating unique identifiers. Consult your database documentation for available options. Additional Tips:

Double-check the spelling of the function name (uuid_generate_v4()). Typos can lead to this error. If you're using an ORM or a framework, refer to its documentation for specific instructions on using UUIDs. They might have built-in functionalities for handling UUID generation.

smartdriver321 commented 4 months ago

@smartdriver321 the error is self-explanatory. do you have .env.local in the root folder of the project which contains POSTGRES_URL? I updated the README.md here: https://github.com/basir/next-15-admin-dashboard?tab=readme-ov-file#run-locally

It is weird my app couldn't read variables in env.local but when I renamed env.local to just .env instead. It worked. I got access to drizzle studio. Now I can finish the whole tutorial. Thanks for the support. Your repo deserved 5 stars

basir commented 4 months ago

sounds good. make sure you import env-config.ts in this file: https://github.com/basir/next-15-admin-dashboard/blob/main/drizzle.config.ts wihtout it, drizzle studio can't read .env.local

cryptodude-go commented 3 months ago

found my mistake. gj also you should do similar dashboard with mongodb. Great job on this tutorial although

basir commented 3 months ago

found my mistake. gj also you should do similar dashboard with mongodb. Great job on this tutorial although

sure, will do.