On using update statement for a POJO in JOOQ I am getting
error: 'column "public" of relation "tableName" does not exist'.
Is there some configuration I am missing for the update statement to work ?
Class MyBook extends com.generated.tables.pojo.Book {
}
com.generated.tables.dao.BookDao.update(MyBook);
It fails with the above mentioned error.
Database: POSTGRES
Related
The entity does not work what is the problem?
#Entity('banks')
export class Banks {
[key: string]: BanksStructure;
constructor(banks?: Partial<Banks>) {
Object.assign(this, banks);
}
}
ERROR [TypeOrmModule] Unable to connect to the database. Retrying (1)...
MissingPrimaryColumnError: Entity "Banks" does not have a primary column. Primary column is required to have in all your entities. Use #PrimaryColumn decorator to add a primary column to your entity.
As the error states your entity does not have a primary column. Please refer to the documentation for specifying it: https://typeorm.io/entities#primary-columns.
Working on nest.js with TypeORM/Postgres.
I've got a calculated_properties column on an entity, like so:
parent.entity.ts
#Entity()
export class Parent {
...
#Column('jsonb')
calculated_properties: CalculatedProperties;
}
calculated_properties.entity.ts
export class CalculatedProperties {
SomeCalc: number,
Other Calc: number,
NestedCalcs: NestedCalc,
With nestedCalc being some other similar types to calculated_properties.entity.ts.
The problem is, when I try to run the app, I get the following error message:
Entity "CalculatedProperties" does not have a primary column. Primary column is required to have in all your entities. Use #PrimaryColumn decorator to add a primary column to your entity.
But I've nowhere said this child type is an entity, and I don't want it to have a PrimaryColumn. In fact, setting an #PrimaryColumn() on it still shows the error - am I missing something obvious here?
This mongoose error was shown when populating collections.
Model.find().populate('someCollection')
This error was generated with the version 6.1.3 of mongoose .
To prevent this horrible fault from mongoose team please downgrade it to 6.1.2
This fixed my problem:
Model.find().populate({path: 'someCollection'})
The error is caused by the reference id that does NOT exist, for example:
the whole item:
{
"_id": "61e21fb9e07c33f81b4cafc4",
"orderItems": [
"61e21fb9e07c33f81b4cafc0", // ref id
"61e21fb9e07c33f81b4cafc1" // ref id
],
...
}
If either of the two ref ids doesn't exist, you'd get the said error:
TypeError: Cannot create property '_fullPath' on string
In that case, you need to discard/delete the whole item, and use the existing ref ids to create a new item.
I am using TypeORM and PostgreSQL in NestJS and I am facing a problem called error: duplicate key value violates unique constraint "message_pkey". I have searched and found out it's a common problem in PostgreSQL, but to solve this problem, I have to write this query:
SELECT setval('TABLENAME_id_seq', (SELECT MAX(id) FROM "TABLENAME"));
// Change TABLENAME with your table
But I can't find how to write this in TypeORM or query builder in NestJS?
Maybe a raw SQL query is a possible solution:
import { getManager } from 'typeorm';
const table = 'tablename';
await getManager().query(`SELECT setval('${table}_id_seq', (SELECT MAX(id) FROM "${table}"))`);
I'm running PostgreSQL 11, and attempting to update one of its table entries using Sequelize.
My NodeJS code:
require('env2')('.env');
const Sequelize = require('sequelize');
const sequelize=new Sequelize(process.env.database,process.env.username,process.env.password,{
dialect:'postgres'
});
const Agent=sequelize.define('agent');
updateValues={available:false};
Agent.update(updateValues,{where:{phonenumber:'+18005551212'}}).then(result=>{console.log(result)});
The table agent has the structure:
id primary key serial,
phonenumber varchar(100),
available boolean
When I run the NodeJS code, I get this error:
Executing (default): UPDATE "agents" SET "updatedAt"='2018-12-27 10:16:54.504 +0
0:00' WHERE "phonenumber" = '+18005551212'
Unhandled rejection SequelizeDatabaseError: relation "agents" does not exist
Why is this update failing? I don't understand why the error is talking about the relation "agents", when I provided the table name as "agent" in sequelize.define(agent).
The update is successful when I use raw SQL as follows:
sequelize.query("update agent set available=false where phonenumber='+18005551212'").then(result=>{
console.log(result);
});
By default sequelize creates a table with a plural of its definition name, so when you do sequelize.define('agent') it actually creates a table with name agents . If you don't want to change your table name naturally you can use freezeTableName: true option in sequelize definition. More can be found in this answer. Refer Sequelize configuration doc
.