Skip to main content
Filter by
Sorted by
Tagged with
1 vote
2 answers
24 views

Foreign Key Mismatch when inserting data in SQLite

I've been trying to insert data in a new table I created with a foreign key referencing another table, but it doesn't seem to work, even when I used the same thing in another table. When I try, for ...
arcanorum's user avatar
0 votes
1 answer
15 views

Which role is responsible for performing `ON UPDATE SET DEFAULT` in PostgreSQL

I'm looking for a confirmation and possible explanation. In PostgreSQL, I create a table A, referencing table B by FK with constrain option ON DELETE UPDATE SET DEFAULT. If the referenced record from ...
pink_daemon's user avatar
0 votes
0 answers
10 views

Sequelize syntax error at or near "ON DELETE" when using associations

I've created a simple express app with a Postgres database using Sequelize as the ORM to define my models. I have two models where there is a one-to-many relationship: A Faction can have many Craters ...
jimjamz's user avatar
  • 69
2 votes
1 answer
31 views

Enforcing two M2M relationships with FK with SQL Server

I have the following entities **Account** Id Name **User** Id Name Users can belong to many accounts. **AccountUser** Id Account_Id FK User_Id Fk Accounts can have many user groups. **...
Elrow's user avatar
  • 21
0 votes
0 answers
18 views

sqlalchemy many to many connection ambiguous foreign keys error

I have an sqlite database within which I am creating several tables. One has a many to many relation though a joining table with another. Upon querying either table for its association, I get ...
Joseph Simon's user avatar
1 vote
1 answer
17 views

In Yii2, is it possible to get the unique objects in a hasMany relation via another hasMany relation?

Say I have an Order model which has some associated Product models, so there's a relation in Order: public function getProducts() { return $this->hasMany(Product::class, ['id' => '...
rosecabbagedragon's user avatar
0 votes
0 answers
11 views

datajoint seems to require schemas to have the same values at shared *secondary* attributes

When trying to join two datajoint tables that have the same values for a primary attribute but different values for a shared secondary attribute ("sweep_key") I am getting this error: ...
Rennie Kendrick's user avatar
0 votes
1 answer
22 views

Cascade Delete in SqlAlchemy One-to-Many relationship made without relationships()

In my FastAPI app, I use sqlalchemy. The main goal of the app is that each user is stored in a sqlalchemy table users and can create different contents (25+ different contents). Each content has its ...
Cesar Mry's user avatar
0 votes
1 answer
29 views

How to model exclusive relation in relational database?

Let there be 3 tables: A, B, C. A row in A may be associated to a row in B, or it may be associated to a row in C, but it must not be associated to both B and C. In other words, the association is an ...
Ivan Rubinson's user avatar
0 votes
0 answers
21 views

Cascading deletion in SQLite with cleanup function needing referenced data

I have a SQLite database structure, together with foreign references, which I'd like to incorporate into my external code logic, but there's a catch... To illustrate my question here's a simplified ...
Solenoid's user avatar
  • 2,371
0 votes
0 answers
50 views

Migration Data - New table already has data & both tables have a self-referencing FK

Environment SQL Server 2019. I have 2 tables with very different schemas, including their PK column's data type. Both tables have a pseudo self-referencing foreign key. By pseudo, I mean that if you ...
Bond's user avatar
  • 89
1 vote
1 answer
37 views

Foreign keys on partitioned tables

What is the best approach to add a foreign key on a partitioned table on Postgresql? 1st approach Add foreign keys on child tables always as NOT VALID. ALTER TABLE <partition_name> ADD ...
Vasileios Giannakidis's user avatar
2 votes
1 answer
93 views

List SQLite Foreign Key Violations C++

I am adding the ability to delete any row in a database for my program, but this database shares keys with 6 other databases. I ensured that foreign keys were enabled to begin with: void ...
Andrew's user avatar
  • 101
1 vote
1 answer
83 views

Entity with UUID relationship error: a foreign key constraint fails. java spring

I'm trying save TaskCard entity TaskCard Service: public TaskCard create(TaskCardCreateData taskCardCreateData) { var creator = authenticatedUserService.getAuthenticatedUser(); var taskCard = ...
Luiz Felipe Burgatt Jolo's user avatar
0 votes
1 answer
21 views

How can I use a field of Foreign key (User Model) as the upload destination of FileField?

I have a Files model which has the User Model as Foreign key, I want to use the user's username as the name of the folder to which the files of the particular user will be uploaded. How can I achieve ...
Khushal's user avatar
  • 729
-2 votes
1 answer
28 views

MySQL ERROR Error Code: 1005. Can't create table (errno: 150 "Foreign key constraint is incorrectly formed") [duplicate]

Tengo la tabla pedidos que hace referencia a la tabla clientes, pero MySQL me dice que la llave foranea no esta bien formada al momento de crear la tabla pedidos. Ya revise el nombre de los campos y ...
Reyes Díaz Diego Joseph's user avatar
0 votes
1 answer
26 views

Getting error Can\'t create table clinic_app_auth.vitals errno: 150 Foreign key constraint is incorrectly formed

I have made the below classes inheriting from BaseModel from sqlalchemy.orm import DeclarativeBase from sqlalchemy.orm import relationship, Mapped, mapped_column class Base(DeclarativeBase): pass ...
Ciasto piekarz's user avatar
0 votes
1 answer
28 views

Laravel HasMany through composite key

I have 1:N relation where parent table LOCATIONS contains fields server_id and location_id and table DEVICES is related to the LOCATIONS throught fields server_id and location_id. How can I establish ...
Čamo's user avatar
  • 4,030
0 votes
1 answer
42 views

Foreign key constraint violation for referencing timescale postgres table

I have postgres timescale table that stores sensor measures. The table has composite primary key with the id int incremental column and the dateTime column(it was required to be composite in oreder to ...
Adzhiew's user avatar
0 votes
1 answer
81 views

Custom cascade delete stored procedure for temporal tables in SQL Server

Preface: I want to create a stored procedure in SQL Server (2016 - v13.0) to manually perform cascading deletes across tables with foreign key constraints, including self-referencing tables. I require ...
ktom's user avatar
  • 144
0 votes
2 answers
91 views

EF Core tries to create a new foreign key when one is already defined

I have two classes that are linked by the foreign key PickingListId. They are both drawing data from SQL views, so I've renamed my PickingList to PickingListView. It worked fine before as it seemed to ...
SkollSunman's user avatar
0 votes
1 answer
28 views

Foreign key constraint vs Application Level Constraint

sorry for my bad english @Entity() export class Account { @PrimaryGeneratedColumn() id: number; @Column({ unique: true }) accountNumber: number; @Column({ type: 'double precision' }) ...
Christian Tiovanto's user avatar
0 votes
1 answer
40 views

Can Not Use Create View in ASP.NET Because of Foreign Key

I have been struggling with foreign key things in my project but to make my point clear, I am going to give you the official tutorial for the relationship things in ASP.NET. I have created these two ...
Abdullah Seçgeler's user avatar
-1 votes
1 answer
71 views

fix Foreign Key constraint in this SQLite3 database?

I'm creating a table of people, and I want to record a table of productions, with the amount each person contributed to that production. So we have a table of share splits; each production earns an ...
Tyr's user avatar
  • 802
1 vote
0 answers
25 views

Why Sequelize migration create my table with only 1 foreing key instead of 2?

Im trying to make a intermediate table between 2 models, called User and Reminder. The fact is everytime i try to migrate or create the table UserReminders I dont get 2 foreing keys, userId and ...
Programador's user avatar
0 votes
1 answer
31 views

Select Rows Based On Foreign Key In One-To-Many Relationships In SQL

I have a posts table and users table. And posts table has a column for author_id (foreign key). This is clearly an example of a One-To-Many relationship. I want to get all posts written by a specific ...
Omar Ahmed's user avatar
-1 votes
1 answer
25 views

test if any object refer to by a base model has a value specified in django orm

Well consider two models: class School(models.Model): name = models.TextField(default="hello world") class Student(models.Model): key = models.TextField(default="somedata")...
paul23's user avatar
  • 9,337
0 votes
1 answer
33 views

How to access set of objects in reverse Foreign Key in Django

I have 2 tables defined like this: class Optimization(BaseModel): name = models.TextField(unique=True, null=False) is_active = models.BooleanField(null=False, default=True) class Meta: ...
Peter Kronenberg's user avatar
0 votes
0 answers
27 views

TypeORM - one-to-one relationship is null

First time using TypeORM, so i'm sorry if it's a very basic issue. I have two entities: user and params: @Entity() export class User { @PrimaryGeneratedColumn() id: number; @Column({ ...
Kaneda's user avatar
  • 132
0 votes
0 answers
33 views

I am trying to access a model using a foreign key in another model in the same models.py file. But I am getting a name "model_name" not defined error

class chaiVariety(models.Model): CHAI_TYPE_CHOICE = [ ('ML', 'MASALA'), ('GR', 'GINGER'), ('KL', 'KIWI'), ('PL', 'PLAIN'), ('EL', 'ELAICHI'), ] name ...
Vibekananda Champati's user avatar
0 votes
0 answers
11 views

Error executing DDL for foreign key constraint in Hibernate with MySQL [duplicate]

I'm encountering an issue with Hibernate while trying to define a foreign key constraint for a MySQL database in my Spring Boot application. I have three entities: Promoteur, Projet, and Bien. The ...
Mohamed Hassany's user avatar
-1 votes
1 answer
51 views

Representing a plant with definite genus but unknown species

I want to represent plants in a database along with their genus/species. This was the schema that came to mind: CREATE TABLE genuses ( id INTEGER PRIMARY KEY, name TEXT UNIQUE NOT NULL); ...
axblount's user avatar
  • 2,653
0 votes
0 answers
33 views

Correct way to create a Games table with 2 player column?

There is a database with tables: Users Tournaments Participants Games Avatar Where, Users is the user model, avatar holds addresses to png files to set avatar for user. Tournament holds tournament ...
Andor Gunczer's user avatar
-1 votes
1 answer
45 views

Foreign keys/Join columns and Join tables are not created by Doctrine in Symfony 5+

In the title I mentioned both Foreign keys and Join tables. In this case, to begin with, I am concerned with Foreign keys. But anyway a Join table is just multiple Foreign keys in a table. It seems ...
Hachem Benyahia's user avatar
1 vote
1 answer
53 views

Entity Framework Core 8.0.6 Isn't Generating Properly Model Throught Foreing Key

I'm using Entity Framework Core using the Database Scaffold. The project is from a social network, and initially we schematized the tables between user and follower as follows: Logical Model of the ...
Sami Daniel's user avatar
0 votes
1 answer
58 views

ASP.NET Entity Framework Core - one-to-many relationship foreign key constraint blocking PUT request

I have a relationship on project and employee entities. I need have added a one-to-many relationship using Entity Framework Core (one employee have many projects, but one project has one employee). ...
salinda yasas's user avatar
0 votes
2 answers
122 views

Type Error while populating a model in Django with UniqueConstraint

I'm trying to build up my first project in Django and I'm having some issues while creating an entry into my model Prevision (including sales forecasts), which has a uniqueConstraint to ensure that ...
grover999's user avatar
  • 337
0 votes
2 answers
92 views

Create a PostgreSQL foreign key reference with default value of NULL

Consider the following table definition: CREATE TABLE containers ( id SERIAL PRIMARY KEY, name VARCHAR(255) NOT NULL, parent_id SERIAL REFERENCES containers(id) ); When I INSERT INTO ...
galah92's user avatar
  • 3,873
0 votes
0 answers
56 views

Hibernate DuplicateMappingException with snake and camelcases. Spring

Migrating some big project from Play to Spring. There is many legacy models in which present separated id of relation nearby. private Long userId; @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(...
Ludov Dmitrii's user avatar
0 votes
1 answer
68 views

Liquibase erroring when creating foreign key - relation "person" does not exist

Using a liquibase changeset I am receiving an error when attempting to create a foreign key when creating a table. If I run the same query against the postgres db it creates the table just fine. Here ...
moff2's user avatar
  • 3
0 votes
0 answers
12 views

Getting TypeError when using FK in my Django Rest code (nested json)

I am trying to use a model as a Foreign key in another model and the result will be a nested json file , so when I modified my code to support it when I call the API using postman I get the following ...
Edi-nano's user avatar
0 votes
0 answers
24 views

JPA Composite Primary and Foreign keys that only share 1 field

I have the following DB model (all fields are not nullable): File SourceTypes ----------- ----------- country PK country PK filename PK sourcetype PK sourcetype sourcename ...
David Caballero's user avatar
-1 votes
1 answer
66 views

How would I update multiple rows in a new foreign key column in an existing table, all with different values?

I have created a database with multiple tables. One table is for products and another is for instructions which go with each product. In the tables, I want to be able to link the two. I've created ...
Lauren Smith's user avatar
1 vote
0 answers
64 views

Foreign keys in Entity Framework Core in an ASP.NET Core Web API

I have a small question and request regarding the code-first approach with Entity Framework Core. Let's suppose I have a class A and a class B. public class A { [Key] public Guid Id { get; set;...
oox's user avatar
  • 19
0 votes
0 answers
35 views

Updating a Foreign Key in Django Rest Framework

these are my models in DRF: class Course(models.Model): title = models.CharField(max_length=100, unique=True) class Prerequisite(models.Model): course = models.ForeignKey(Course, on_delete=...
Nikolat's user avatar
0 votes
0 answers
33 views

Reintroduce Foreign Keys where data is mismatched

I need to change a PK to clustered. For this I need to drop the constraint and recreate this. But I can't drop until removing the FK's. I can drop the FK and change the PK. But, recreating the FK ...
Kieran's user avatar
  • 656
0 votes
0 answers
36 views

Relationship problem with SQLAlchemy and SQLite in Python

I created a db in SQLite and added tables with SQLAlchemy. DB_URL = "sqlite:///wimp.sqlite3" engine = create_engine(DB_URL, echo=True) Session = sessionmaker(autocommit=False, autoflush=...
Marco's user avatar
  • 1
2 votes
1 answer
494 views

Does SwiftData give a model a primary key?

If I use @Model to tell SwiftData to persist a class with its properties, does it add a property to use as a primary key? And if so, is it an incrementing integer? What is it called? Is that key used ...
schwabsauce's user avatar
0 votes
1 answer
37 views

SQLAlchemy 2.0 foreign key across parent and child tables

Say I have these tables which define hierarchy Org id name SubOrg id org_id name Now there is another table which refers both such that: Rules id org_id sub_org_id (nullable) ... The way Rules ...
MavWolverine's user avatar
0 votes
0 answers
159 views

Supabase inserting into a foreign key table through triggered function

Issue I'm trying to use an Edge Function to insert rows into a table named weather_logs. The function will be called from an AFTER INSERT trigger on locations. What's causing the issue is that ...
Jhsu's user avatar
  • 13

1
2 3 4 5
229