我正在使用下面的代码通过 db 中的发布请求将我的行详细信息放入,但错误来了:
(insert into `product` (`created_at`, `description`, `id`, `image`,`pages`, `title`, `updated_at`)
values ('2021-02-14 02:44:52', 'sddsds', 12, 'image', '23', 's', '2021-02-14 02:44:52') -
ER_BAD_FIELD_ERROR: Unknown column 'created_at' in 'field list').
我正在/products/
用身体击打:
{
"productId": 12,
"description": "sddsds",
"title": "s",
"image":"image",
"pages": "23"
}
路线 :
Route.resource("products", "ProductsController");
我的Product
控制器:
async store({ request, response }: HttpContextContract) {
const { productId, description, title, image, pages } = request.post()
// save and get instance back
const product = await Product.create({ productId, description, title, image, pages })
response.status(201).json({
message: 'Successfully created a new product.',
data: product
})
}
我的Product
模型:
import { DateTime } from 'luxon'
import { BaseModel, column, computed, hasMany, HasMany } from '@ioc:Adonis/Lucid/Orm'
import Price from './Price'
export default class Product extends BaseModel {
public static table = 'product'
@column({ isPrimary: true, columnName: 'id', serializeAs: 'productId' })
public productId: number
@column({ columnName: 'title' })
public name: string
@column({ serialize: (v) => (v ? v : undefined) })
public description: string
@column({ serialize: (v) => (v ? v : undefined) })
public image: string
@column({ serialize: (v) => (v ? v : undefined) })
public pages: string
@column.dateTime({ autoCreate: true })
public createdAt: DateTime
@column.dateTime({ autoCreate: true, autoUpdate: true })
public updatedAt: DateTime
@hasMany(() => Price, {
foreignKey: 'productId',
onQuery: (query) => query.whereNull('deleted_at'),
serializeAs: null,
})
public prices: HasMany<typeof Price>
@computed({ serializeAs: 'price' })
public get price() {
if (this.prices && this.prices.length) {
return this.prices[0].originalPrice
}
return 0
}
@computed()
public get quantityInCart() {
return this.$extras.pivot_quantity
}
}