I have a table
company and other group and product table
the product table has a foreign key (FK) which is the company ID, when I add information through:
await strapi.services.product.create({
'name': data.name,
'company': ids.idCompany, //FK
'price': data.price,
'on_off': data.onOff,
'cod': data.cod.toString(),
'groups': data.idGrup //FK
})
pass the data and generate the error:
The ‘groups’ field does not have a default value
or
The ‘company’ field does not have a default value
const result = await knex('products')
.insert({
'name': data.name,
'price': data.price,
'company': ids.idCompany,
'on_off': data.onOff,
'cod': data.cod.toString(),
'groups': data.idGrup
To change this error you have to use the knex.
Another interesting thing is that strapi does not create foreign keys, but only a field with an int value and that field can receive anything as long as it is integer.
for example:
tebela company
id (PK)
name varchar
product table
id (PK)
name vahcar
company int (FK)