next-learn
next-learn copied to clipboard
Chapter 6: Cannot seed database
Hi Team,
I trust this message finds you in good spirits. 🌟 Your commitment to the project is truly appreciated, and we welcome your active involvement.
We've identified an issue post-seeding the database. Although the storage isn't empty, there are discrepancies we need your expertise to address:
Description: After seeding the database, non-empty storage is observed.
However, when checking the tables list, it appears to be empty, and the connection status remains stuck at Connecting:
This discrepancy is hindering the expected behavior of the system. We would greatly appreciate your insights and contributions to resolve this issue.
Details:
Issue Title: Database Seeding Discrepancy Description: Non-empty storage, yet tables list is empty, and connection status is Connecting.
Thank you for your ongoing support!
Actually issue is reproducing on macOS, while on Windows I can see Connected
status in Storage -> Dashobard -> Data
Thank you for reporting this @daweed311, are you still seeing this issue in the Vercel dashboard?
Yes, only on macOS device
I am experiencing the same issue on Windows in addition to the missing_connecting_string error after running the seeding command.
An error occurred while attempting to seed the database: VercelPostgresError: VercelPostgresError - 'missing_connection_string': You did not supply a 'connectionString' and no 'POSTGRES_URL' env var was found.
Hi !
Just rename .env.local to .env worked for me
$ npm run seed
seed node -r dotenv/config ./scripts/seed.js
node:events:492 throw er; // Unhandled 'error' event ^
Error: getaddrinfo ENOTFOUND ep-cool-butterfly-22386990-pooler.ap-southeast-1.postgres.vercel-storage.com
at GetAddrInfoReqWrap.onlookup [as oncomplete] (node:dns:108:26)
Emitted 'error' event on WebSocket instance at:
at emitErrorAndClose (D:\projects\nextjs-dashboard\node_modules\ws\lib\websocket.js:1016:13)
at ClientRequest.
Node.js v18.17.0
I did. But not working for me
Having similiar issue (please note this issue is not the connection string issue, slightly different). This symptom has been sited 3 times now (I am on windows, fyi)
- https://github.com/vercel/next-learn/issues/476
- https://github.com/vercel/next-learn/issues/484#issuecomment-1849731025
Solutions that will not work for me:
- adding POSTGRES_URL (it is specified as can be seen in stacktrace below)
- Renaming .env.development.local OR a .env.local file suggestion. These do NOT exist, I only had .env.example
npm run seed
> seed
> node -r dotenv/config ./scripts/seed.js
node:events:496
throw er; // Unhandled 'error' event
^
Error: getaddrinfo ENOTFOUND ep-icy-cell-a47ky353-pooler.us-east-1.postgres.vercel-storage.com
at GetAddrInfoReqWrap.onlookupall [as oncomplete] (node:dns:118:26)
Emitted 'error' event on WebSocket instance at:
at emitErrorAndClose (C:\work\projects\nextjs-dashboard\node_modules\ws\lib\websocket.js:1016:13)
at ClientRequest.<anonymous> (C:\work\projects\nextjs-dashboard\node_modules\ws\lib\websocket.js:864:5)
at ClientRequest.emit (node:events:518:28)
at TLSSocket.socketErrorListener (node:_http_client:495:9)
at TLSSocket.emit (node:events:518:28)
at emitErrorNT (node:internal/streams/destroy:169:8)
at emitErrorCloseNT (node:internal/streams/destroy:128:3)
at process.processTicksAndRejections (node:internal/process/task_queues:82:21) {
errno: -3008,
code: 'ENOTFOUND',
syscall: 'getaddrinfo',
hostname: 'ep-icy-cell-a47ky353-pooler.us-east-1.postgres.vercel-storage.com'
}
Node.js v20.11.0
Ideas?
attached a version of data.ts that is an avoidance of the database (and the database issue). Might be useful until someone solves what this problem is. data.txt
I'm facing the same issue on a Mac M1 with postgresql installed using brew and POSTGRES_URL properly set (ie I can connect using psql with the same url)
node: v18.19.0
Hi !
Just rename .env.local to .env worked for me
Thanks , it worked for me too I was stuck for atleast 1 hour coz of this problem 🙃
Hi ! Just rename .env.local to .env worked for me
Thanks , it worked for me too I was stuck for atleast 1 hour coz of this problem 🙃
I have no .env.local, I had .env.example, which I renamed to .env (as per the tutorial). This did NOT fix it.
Hi ! Just rename .env.local to .env worked for me
Thanks , it worked for me too I was stuck for atleast 1 hour coz of this problem 🙃
I have no .env.local, I had .env.example, which I renamed to .env (as per the tutorial). This did NOT fix it.
share the screeshot if you can
Hi ! Just rename .env.local to .env worked for me
Thanks , it worked for me too I was stuck for atleast 1 hour coz of this problem 🙃
I have no .env.local, I had .env.example, which I renamed to .env (as per the tutorial). This did NOT fix it.
share the screeshot if you can
See https://github.com/vercel/next-learn/issues/484#issuecomment-1920045791 for details
@daweed311 did you find any solution for this?
no just used static file (to avoid db usage) i attached to issue.
@daweed311 did you find any solution for this?
Unfortunately, no. I completed this tutorial on a Windows device.
The sql is all wrong.
const users = [ { id: '410544b2-4001-4271-9855-fec4b6a6442a', name: 'User', email: '[email protected]', password: '123456', }, ];
Attempting to insert this data leads to An error occurred while attempting to seed the database: error: trailing junk after numeric literal at or near "410544b"
So basically, the placeholder-js data needs to be sanitized and not evalulate to something else. Postgres is thinking that subtraction is being done due to absence of correct quotes.
Yes, @openSourceBugs comment is correct.
You need to take 2 steps to fix it:
- Use double quotations in the
placeholder-daja.js
JSON values (as shown below), because the Template Literals (backticks) strings on theseed.js
queries are being rendered without single quotes in the values, so they fail. I've attached the fixed JS file, and a snippet below if you wanna do it by hand.
const users = [
{
id: "'410544b2-4001-4271-9855-fec4b6a6442a'",
name: "'User'",
email: "'[email protected]'",
password: "'123456'",
},
];
-
hashedPassword
is a calculated value (doesn't come from the placeholders) so it needs to be fixed in situ:\'${hashedPassword}\'
(by adding single quotation marks onseed.js
)
Optional:
If you are trying to run the tutorial without connecting to Vercel's cloud, and the @vercel/postgres
database client is giving you problems, you can replace it completely with node-postgres
.
Just install it with npm install node-postgres
then import it in replacement of Vercel's:
//const { db } = require('@vercel/postgres');
const { Client } = require('pg');
const client = new Client({
user: 'postgres',
password: 'PASSWORD',
host: 'localhost',
port: '5432',
database: 'nextjs-dashboard-postgres',
});
If you don't set the Config dictionary, it will take the environment variables, just like Vercel's.
And replace all the client.sql
with client.query(...)
in seed.js
like this:
await client.query(`CREATE EXTENSION IF NOT EXISTS "uuid-ossp"`);
// Create the "users" table if it doesn't exist
const createTable = await client.query(`
CREATE TABLE IF NOT EXISTS users (
id UUID DEFAULT uuid_generate_v4() PRIMARY KEY,
name VARCHAR(255) NOT NULL,
email TEXT NOT NULL UNIQUE,
password TEXT NOT NULL
);
`);
And finally, fix the main function:
async function main() {
await client.connect();
await seedUsers(client);
await seedCustomers(client);
await seedInvoices(client);
await seedRevenue(client);
await client.end();
}
These changes made the trick for me.
Cheers!
The sql is all wrong.
const users = [ { id: '410544b2-4001-4271-9855-fec4b6a6442a', name: 'User', email: '[email protected]', password: '123456', }, ];
Attempting to insert this data leads to An error occurred while attempting to seed the database: error: trailing junk after numeric literal at or near "410544b"
So basically, the placeholder-js data needs to be sanitized and not evalulate to something else. Postgres is thinking that subtraction is being done due to absence of correct quotes.
Yes, @openSourceBugs comment is correct.
You need to take 2 steps to fix it:
- Use double quotations in the
placeholder-daja.js
JSON values (as shown below), because the Template Literals (backticks) strings on theseed.js
queries are being rendered without single quotes in the values, so they fail. I've attached the fixed JS file, and a snippet below if you wanna do it by hand.const users = [ { id: "'410544b2-4001-4271-9855-fec4b6a6442a'", name: "'User'", email: "'[email protected]'", password: "'123456'", }, ];
hashedPassword
is a calculated value (doesn't come from the placeholders) so it needs to be fixed in situ:\'${hashedPassword}\'
(by adding single quotation marks onseed.js
)Optional:
If you are trying to run the tutorial without connecting to Vercel's cloud, and the
@vercel/postgres
database client is giving you problems, you can replace it completely withnode-postgres
.Just install it with
npm install node-postgres
then import it in replacement of Vercel's://const { db } = require('@vercel/postgres'); const { Client } = require('pg'); const client = new Client({ user: 'postgres', password: 'PASSWORD', host: 'localhost', port: '5432', database: 'nextjs-dashboard-postgres', });
If you don't set the Config dictionary, it will take the environment variables, just like Vercel's.
And replace all the
client.sql
withclient.query(...)
inseed.js
like this:await client.query(`CREATE EXTENSION IF NOT EXISTS "uuid-ossp"`); // Create the "users" table if it doesn't exist const createTable = await client.query(` CREATE TABLE IF NOT EXISTS users ( id UUID DEFAULT uuid_generate_v4() PRIMARY KEY, name VARCHAR(255) NOT NULL, email TEXT NOT NULL UNIQUE, password TEXT NOT NULL ); `);
And finally, fix the main function:
async function main() { await client.connect(); await seedUsers(client); await seedCustomers(client); await seedInvoices(client); await seedRevenue(client); await client.end(); }
These changes made the trick for me.
Cheers!
The sql is all wrong. const users = [ { id: '410544b2-4001-4271-9855-fec4b6a6442a', name: 'User', email: '[email protected]', password: '123456', }, ]; Attempting to insert this data leads to An error occurred while attempting to seed the database: error: trailing junk after numeric literal at or near "410544b" So basically, the placeholder-js data needs to be sanitized and not evalulate to something else. Postgres is thinking that subtraction is being done due to absence of correct quotes.
Jesus, thank you man, underrated comment
Comment ajoutées des données à la base de données vercel/postgres lors d'une sumission de formulaire
@daweed311 hey there! I have solved this by changing the node version according to package.json.
file name Edit .env.example -> .env
still this isn't working on MacOs
Hi !
Just rename .env.local to .env worked for me
It's worked for me! Thanks.
@daweed311 just you need to update the node version
It worked for me
I am not able to reproduce this. Please open a new issue if you are still having trouble here. Thank you!
We are also making the seeding easier in this PR by allowing you to hit a URL in the browser: https://github.com/vercel/next-learn/pull/764