foreign-keys

delete not cascaded to table in sqlalchemy

旧街凉风 提交于 2021-02-04 18:40:30
问题 I am developing an extension to an existing app which uses sqlalchemy 0.6. The app has sqlalchemy tables created the non-declarative way. I am trying to create in my extension a new table with a foreign key column pointing at the primary key of the main table in the application database and I am creating it declaratively. This all works fine, with the table created once the extension is loaded, and with no complaints at all. My table prints out and demonstrates that new rows have been added

mariadb won't create foreign key

泪湿孤枕 提交于 2021-01-29 10:54:13
问题 I think I'm using the right syntax for MariaDB, but my foreign key constraint is not being created. Here's the create table DDL: CREATE TABLE items ( id INT auto_increment primary key, description TEXT NOT NULL ); CREATE TABLE item_events ( id INT NOT NULL, calendar_event_guid TEXT(255) NOT NULL, foreign key item_events_id_fk (id) REFERENCES items (id) ); Then, when I ask MariaDB to show me what I created, I get this: +-------------+----------------- | Table | Create Table +-------------+----

SQLSTATE[23000]: Integrity constraint violation: 1048 laravel

随声附和 提交于 2021-01-29 10:42:20
问题 I'm getting the following MYSQL error while trying to attach products to an order: SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'order_id' cannot be null (SQL: insert into order_product ( amount , history_price , order_id , product_id ) values (1, 5.35, , )) I've already searched for a solution, however all solutions I managed to find seemed to talk about not using default laravel id's as primary keys, while I am using default ID's. Here are the three migrations: Schema:

Postgres: drop foreign key constraint query getting stuck

北慕城南 提交于 2021-01-29 09:52:17
问题 I wanted to remove all foreign key constraints from a schema. I was successful in dropping constraints from most of the tables but in few of them drop foreign key constraint query is getting stuck. ALTER TABLE table_name DROP CONSTRAINT fkey_name; I tried truncate cascade but it was also getting stuck. I deleted all rows from both the tables manually. Still getting stuck. Edits: By getting stuck I mean query continues running for long time without any error message even though tables are

Foreign key referring to multiple rows in another table

久未见 提交于 2021-01-29 02:36:11
问题 I am working with MySQL, trying to build an online vehicles database system. For this purpose, I created two tables: vehicles and owners. create table vehicles ( v_id int AUTO_INCREMENT PRIMARY KEY, v_reg_number varchar(255) unique, v_engine_number varchar(255) unique, v_chassis_number varchar(255) unique, v_type varchar(255), v_manufacturer varchar(255), v_model_year varchar(255), v_power varchar(255), v_origin varchar(255) ) create table owners ( o_id int AUTO_INCREMENT PRIMARY KEY, v_id

How to populate one to many relationship in mongoose with parent refrencing?

会有一股神秘感。 提交于 2021-01-28 21:31:06
问题 I have three collections: parent, child1, child2. parent collection: [{_id:1}, {_id:2}, {_id:3}] child1 collection: [{_id:1, child1:'a', parent:1}, {_id:2, child1:'b', parent:1}, {_id:3, child1:'c', parent:2}] child2 collection: [{_id:1, child1:'d', parent:2}, {_id:2, child1:'e', parent:3}] collections child1 and child2 referenced to parent collection. now, I want a query in mongoose to get a result like this: [ { _id:1, child1:[{_id:1, child1:'a'}, {_id:2, child1:'b'}], child2:[], }, { _id:2

Why is the “on_update” option not present in Django Relationship fields?

半腔热情 提交于 2021-01-28 19:27:42
问题 I'm using Django 3.0 + MariaDB. I've created a models.py from an existent database with the "python manage.py inspectdb > models.py" command. I need now to set the options for the Foreign Keys. As you know in a database you can have multiple options for the Foreign Keys: the first classic is "ON_DELETE" and the second is 'ON_UPDATE' (You can even have more options in PostgreSQL). In Django, there is just an "on_delete", but no "on_update" option, what I found very surprising. I found nothing

Why is the “on_update” option not present in Django Relationship fields?

人盡茶涼 提交于 2021-01-28 19:20:59
问题 I'm using Django 3.0 + MariaDB. I've created a models.py from an existent database with the "python manage.py inspectdb > models.py" command. I need now to set the options for the Foreign Keys. As you know in a database you can have multiple options for the Foreign Keys: the first classic is "ON_DELETE" and the second is 'ON_UPDATE' (You can even have more options in PostgreSQL). In Django, there is just an "on_delete", but no "on_update" option, what I found very surprising. I found nothing

KeyError on relation field in Django-REST

 ̄綄美尐妖づ 提交于 2021-01-28 18:18:11
问题 I have the following models: class ProductColor(models.Model): color_title = models.CharField(max_length=50) class BasicProduct(models.Model): product_title = models.CharField(max_length=150) product_desc = models.TextField() product_price = models.FloatField(default=10.0) # Describes what colors are available for this product product_colors = models.ManyToManyField(ProductColor) class BasicCartItem(models.Model): cart_product = models.ForeignKey(BasicProduct) cart_color = models.ForeignKey

SQL error - Cannot add foreign key constraint

孤街醉人 提交于 2021-01-28 12:11:07
问题 I am trying to create some tables in a database with java (jdbc). The "code" underneath is just two strings, each containing an SQL CREATE TABLE update, one for the table "store_sales" and one for the table "store_returns" I get java.sql.SQLException: Cannot add foreign key constraint that happens when I try to make store_returns.sr_ticket_number a foreign key referencing store_sales.ss_ticket_number in the last line of the "code" Any ideas? Thanks in advance. "CREATE TABLE IF NOT EXISTS