erreur in request preload #4343
Unanswered
dev-passion76
asked this question in
Help
Replies: 2 comments
-
Hey! Check your PS. Please preview your message before creating, as broken markup makes the problem difficult to understand. |
Beta Was this translation helpful? Give feedback.
0 replies
-
hello aikrom thank for your help , all is done now and i understand now . bye and than you again |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
hello
i have this error when a make this request
` public async get_all({ response }: HttpContextContract) {
}`
error
select * from
productswhere
category_idin (1) - Unknown column 'category_id' in 'where clause' err: { "type": "Error", "message": "select * from
productswhere
category_idin (1) - Unknown column 'category_id' in 'where clause'", "stack": Error: select * from
productswhere
category_idin (1) - Unknown column 'category_id' in 'where clause' at Packet.asError (D:\adonis_project\lachtinormande_api\node_modules\mysql2\lib\packets\packet.js:728:17) at Query.execute (D:\adonis_project\lachtinormande_api\node_modules\mysql2\lib\commands\command.js:29:26) at Connection.handlePacket (D:\adonis_project\lachtinormande_api\node_modules\mysql2\lib\connection.js:478:34) at PacketParser.onPacket (D:\adonis_project\lachtinormande_api\node_modules\mysql2\lib\connection.js:97:12) at PacketParser.executeStart (D:\adonis_project\lachtinormande_api\node_modules\mysql2\lib\packet_parser.js:75:16) at Socket.<anonymous> (D:\adonis_project\lachtinormande_api\node_modules\mysql2\lib\connection.js:104:25) at Socket.emit (node:events:518:28) at addChunk (node:internal/streams/readable:559:12) at readableAddChunkPushByteMode (node:internal/streams/readable:510:3) at Socket.Readable.push (node:internal/streams/readable:390:5) "code": "ER_BAD_FIELD_ERROR", "errno": 1054, "sqlState": "42S22", "sqlMessage": "Unknown column 'category_id' in 'where clause'", "sql": "select * from
productswhere
category_idin (1)", "status": 500 }
my migrations categories
`import BaseSchema from "@IOC:Adonis/Lucid/Schema";
export default class extends BaseSchema {
protected tableName = "categories";
public async up() {
this.schema.createTable(this.tableName, (table) => {
table.increments("id");
}
public async down() {
this.schema.dropTable(this.tableName);
}
}
`
migration products
`import BaseSchema from '@IOC:Adonis/Lucid/Schema'
export default class extends BaseSchema {
protected tableName = 'products'
public async up () {
this.schema.createTable(this.tableName, (table) => {
table.increments('id')
table.integer("ordre").notNullable().unique().defaultTo(0);
table.string("imageSrc");
table.string("imageAlt");
table.string("title");
table.string("description");
table.integer("price");
table.integer("like");
table.boolean("isActive").notNullable().defaultTo(false);
}
public async down () {
this.schema.dropTable(this.tableName)
}
}
`
my models category
`import { DateTime } from "luxon";
import { BaseModel, HasMany, column, hasMany } from "@IOC:Adonis/Lucid/Orm";
import Product from "./Product";
export default class Category extends BaseModel {
@column({ isPrimary: true })
public id: number;
@column()
public ordre: number;
@column()
public name: string;
@column()
public isactive: boolean;
@hasmany(() => Product, {
foreignKey: 'categoryId',
})
public products: HasMany
@column.dateTime({ autoCreate: true })
public createdAt: DateTime;
@column.dateTime({ autoCreate: true, autoUpdate: true })
public updatedAt: DateTime;
}
`
my model product
`import { DateTime } from 'luxon'
import { BaseModel, BelongsTo, belongsTo, column } from '@IOC:Adonis/Lucid/Orm'
import Category from './Category';
export default class Product extends BaseModel {
@column({ isPrimary: true })
public id: number
@column()
imageSrc: string;
@column()
imageAlt: string;
@column()
title: string;
@column()
description: string;
@column()
price: number;
@column()
likes: number;
@column()
public categoryId: number
@column.dateTime({ autoCreate: true })
public createdAt: DateTime
@column.dateTime({ autoCreate: true, autoUpdate: true })
public updatedAt: DateTime
}
`
please if you have an idea ,
thank you
Beta Was this translation helpful? Give feedback.
All reactions