Sequelizemodule - Autoloadmodels / [Nest] Fehler -Folgesexizemodule kann nicht zur Datenbank hergestellt werden. WiederhJavaScript

Javascript-Forum
Anonymous
 Sequelizemodule - Autoloadmodels / [Nest] Fehler -Folgesexizemodule kann nicht zur Datenbank hergestellt werden. Wiederh

Post by Anonymous »

Ich lerne NestJs, ich versuche, über ein Fortsetzung des Moduls mit meiner lokalen Postgres -Datenbank eine Verbindung herzustellen, aber ich erhalte diesen Fehler weiter
< /h4>
Fehler beim Start: Start: dev < /p>

Code: Select all

[20:41:14] Starting compilation in watch mode...

[20:41:26] Found 0 errors. Watching for file changes.

[Nest] 14312  - 16.02.2025, 20:41:44     LOG [NestFactory] Starting Nest application...
[Nest] 14312  - 16.02.2025, 20:41:46     LOG [InstanceLoader] AppModule dependencies initialized +1744ms
[Nest] 14312  - 16.02.2025, 20:41:46     LOG [InstanceLoader] SequelizeModule dependencies initialized +0ms
[Nest] 14312  - 16.02.2025, 20:41:46     LOG [InstanceLoader] UsersModule dependencies initialized +1ms
[Nest] 14312  - 16.02.2025, 20:41:46     LOG [InstanceLoader] ConfigHostModule dependencies initialized +0ms
[Nest] 14312  - 16.02.2025, 20:41:46     LOG [InstanceLoader] ConfigModule dependencies initialized +0ms
Executing (default): SELECT 1+1 AS result
Executing (default): SELECT table_name FROM information_schema.tables WHERE table_schema = 'public' AND table_name = 'users'
Executing (default): CREATE TABLE IF NOT EXISTS "users" ("id" NUMBER SERIAL UNIQUE , "email" VARCHAR(255) NOT NULL UNIQUE, "password" VARCHAR(255) NOT NULL, "banned" BOOLEAN DEFAULT false, "banReason" VARCHAR(255), "createdAt" TIMESTAMP WITH TIME ZONE NOT NULL, "updatedAt" TIMESTAMP WITH TIME ZONE NOT NULL, PRIMARY KEY ("id"));
[Nest] 14312  - 16.02.2025, 20:41:46   ERROR [SequelizeModule] Unable to connect to the database. Retrying (1)...
Error
at Query.run (D:\IT\IT\PROJECTS\my_projects\ulbi\backend_node_nest_docker\node_modules\sequelize\src\dialects\postgres\query.js:76:25)
at  (D:\IT\IT\PROJECTS\my_projects\ulbi\backend_node_nest_docker\node_modules\sequelize\src\sequelize.js:650:28)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at PostgresQueryInterface.createTable (D:\IT\IT\PROJECTS\my_projects\ulbi\backend_node_nest_docker\node_modules\sequelize\src\dialects\abstract\query-interface.js:229:12)
at Function.sync (D:\IT\IT\PROJECTS\my_projects\ulbi\backend_node_nest_docker\node_modules\sequelize\src\model.js:1353:7)
at Sequelize.sync (D:\IT\IT\PROJECTS\my_projects\ulbi\backend_node_nest_docker\node_modules\sequelize\src\sequelize.js:825:9)
at async D:\IT\IT\PROJECTS\my_projects\ulbi\backend_node_nest_docker\node_modules\@nestjs\sequelize\dist\sequelize-core.module.js:123:17
< /code>
Zu Beginn findet man anscheinend einige Manipulationen statt, aber dann wird ein Fehler geworfen, ohne zu erklären, was passiert ist (zumindest sehe ich hier nichts Nützliches) und dann zehnmal Fehler Nach dem Fehler ...
< /p>
 Verbinden von Sequelizemodule in app.module < /h5>
import { Module } from '@nestjs/common';
import { SequelizeModule } from '@nestjs/sequelize';
import { UsersModule } from './users/users.module';
import { ConfigModule } from '@nestjs/config';
import { User } from './users/users.model';

@Module({
controllers: [],
providers: [],
imports: [
ConfigModule.forRoot({
envFilePath: `.${process.env.NODE_ENV}.env`
}),
SequelizeModule.forRoot({
dialect: 'postgres',
host: process.env.POSTGRES_HOST,
port: Number(process.env.POSTGRES_PORT),
username: process.env.POSTGRES_USER,
password: String(process.env.POSTGRES_PASSWORD),
database: process.env.POSTGRES_DB,
models: [User],
autoLoadModels: false
}),
UsersModule,
],
})
export class AppModule {}
< /code>
PS: Kennwort über String (), da es aus irgendeinem Grund schimpfte, dass es sich nicht um eine String handelte ... < /p>
 verwendete bei Benutzern.  Modul < /h5>
import { Module } from '@nestjs/common';
import { UsersController } from './users.controller';
import { UsersService } from './users.service';
import { SequelizeModule } from '@nestjs/sequelize';
import { User } from './users.model';

@Module({
controllers: [UsersController],
providers: [UsersService],
imports: [
SequelizeModule.forFeature([User]),
]
})
export class UsersModule {}
< /code>
 < /h5>
.Env -Datei < /p>
PORT=5000
POSTGRES_HOST=localhost
POSTGRES_USER=postgres
POSTGRES_PASSWORD=admin
POSTGRES_PORT=5432
POSTGRES_DB=ulbi-nest-course
< /code>

 < /H2>
Ich habe einige gesucht und festgestellt, dass es sich um die Option handelt >
 Ich habe versucht, es auf false festzulegen, und der Fehler verschwand wirklich, aber ... < /h4>
IMG No Fehler < /p>
[20:43:19] Starting compilation in watch mode...

[20:43:23] Found 0 errors. Watching for file changes.

[Nest] 28912  - 16.02.2025, 20:43:25     LOG [NestFactory] Starting Nest application...
[Nest] 28912  - 16.02.2025, 20:43:25     LOG [InstanceLoader] AppModule dependencies initialized +162ms
[Nest] 28912  - 16.02.2025, 20:43:25     LOG [InstanceLoader] SequelizeModule dependencies initialized +0ms
[Nest] 28912  - 16.02.2025, 20:43:25     LOG [InstanceLoader] SequelizeCoreModule dependencies initialized +0ms
[Nest] 28912  - 16.02.2025, 20:43:25     LOG [InstanceLoader] UsersModule dependencies initialized +1ms
[Nest] 28912  - 16.02.2025, 20:43:25     LOG [InstanceLoader] ConfigHostModule dependencies initialized +0ms
[Nest] 28912  - 16.02.2025, 20:43:25     LOG [InstanceLoader] SequelizeModule dependencies initialized +0ms
[Nest] 28912  - 16.02.2025, 20:43:25     LOG [InstanceLoader] ConfigModule dependencies initialized +0ms
[Nest] 28912  - 16.02.2025, 20:43:25     LOG [RoutesResolver] UsersController {/users}: +6ms
[Nest] 28912  - 16.02.2025, 20:43:25     LOG [NestApplication] Nest application successfully started +3ms
Listening on port 5000
< /code>
 Absolut nichts ist in der Datenbank passiert > Während ich Benutzer habe.import { Column, DataType, Model, Table } from 'sequelize-typescript';

interface UserCreationAttrs {
email: string,
password: string,
}

@Table({tableName: 'users'})
export class User extends Model {
@Column({type: DataType.NUMBER, unique: true, autoIncrement: true, primaryKey: true})
id: number;

@Column({type: DataType.STRING, unique: true, allowNull: false})
email: string;

@Column({type: DataType.STRING, allowNull: false})
password: string;

@Column({type: DataType.BOOLEAN, defaultValue: false})
banned: boolean;

@Column({type: DataType.STRING, allowNull: true})
banReason: string;
}

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post