13,134 questions
Best practices
0
votes
2
replies
73
views
PhpMyadmin Is it possible to create a foreign key from multiple foreign keys
Table Schema
Like in my picture.
I have a Table that contains ID´s(fk).
If i hover over one of them it shows me the Value.
Then i have another Table that contains the ID from the previous Table.
Is it ...
Best practices
0
votes
5
replies
95
views
How to handle a “ghost” product in a SellDetails table without breaking normalization?
I'm developing a desktop application for gym management. One feature is a store for selling memberships and products.
My client sometimes wants to sell something that is not in the inventory or ...
6
votes
3
answers
209
views
Preserve a foreign key using a uniqueness constraint while dropping a primary constraint
I have a SQL Server database I mostly interact with using EF Core in a .NET project: I'll analogize my domain logic for simplicity.
I have a Fruits table holding general fruit data in columns Weight, ...
2
votes
3
answers
103
views
Why does my Django models.Manager return all objects on a relationship?
I don't particularly understand what's going on here, but it seems that super().get_queryset() doesn't do what I think it does?
I have 1:N relationship, and the default FK reverse lookup works:
>&...
1
vote
1
answer
57
views
set model field to one of the values it is paired with in another model
class Company(models.Model):
note = models.TextField(_('note'), blank=True, null=True)
class Meta:
verbose_name = _('Company')
def __str__(self):
return f'{self.id}'
Each ...
-1
votes
1
answer
140
views
Why do I get an index error when adding a column to a MySQL table? [closed]
I want to alter a table called mvp to add a column. When I run the alter statement, I get an index error:
**ERROR 1553 (HY000):** Cannot drop index '<unknown key name>': needed in a foreign key ...
0
votes
0
answers
42
views
Foreign key does not appear in table structure in PHPMYADMIN
I am creating two tables called customer and item.
For the customer table customerID is the primary key and for the item table itemID is the primary key. And I am creating another table which is ...
-1
votes
1
answer
47
views
MySQL Adding Foreign Key Constraint to Table Using a JSON Expression
I am trying to add an index and a foreign key constraint to an existing table, each of which references a JSON expression.
The ADD INDEX command below is working by itself, but the statement fails ...
1
vote
1
answer
36
views
How to refresh a foreign key list in QSqlRelationalTableModel
In a Qt 6.8.2 Desktop application with SQLite I have two related tables:
Table master
id
name
1
aaa
2
bbb
Table details
id
idMaster
value
1
1
foo
2
1
bar
In my QMainWindow I have two QTableView and I ...
0
votes
2
answers
61
views
Spring boot @OneToMany and @ManyToOne don't save foreign key
I am using @OneToMany and @ManyToOne in spring boot and when I try to save to the database (PostgresSQL) the foreign key is not saved. I tried to follow all the instructions and settings described but ...
0
votes
1
answer
122
views
How can I use ALTER TABLE to add a column that is NOT NULL and REFERENCES?
I want to add a column of type TEXT, NOT NULL, with a DEFAULT value of empty string, which should reference a column in a different table. I can add foreign key references when creating a table.
But ...
-2
votes
2
answers
77
views
SQL table design with foreign key [closed]
I have two tables:
Product
Columns: Product ID (PK), Product Name
Order
Columns: Order ID (PK), Order Name
I would like to store which Product Id for each order.
Is it better to create another table:
...
-1
votes
1
answer
50
views
I am getting a error: everse for 'genre' with arguments '('',)' not found. 1 pattern(s) tried: ['genres/(?P<genre_id>[0-9]+)\\Z']
am trying to run a Django site but have a error when i click on this url:
'book:genres'
this is the error:
Reverse for 'genre' with arguments '('',)' not found. 1 pattern(s) tried: ['genres/(?P<...
-1
votes
1
answer
45
views
Multipe one-to-many relation between two models
I was creating a route finder and I created a vehicle model with relations start_location and final_location. I want them to be foreign keys as I don't want to have multiple options when selecting ...
0
votes
0
answers
19
views
Trigger in SQLite to transparently handle dictionary (foreign key)
I have the following table:
create table if not exists balance (
id integer PRIMARY KEY AUTOINCREMENT,
exchange integer,
FOREIGN KEY (exchange) REFERENCES exchanges(id)
);
where the field ...
0
votes
0
answers
26
views
How to pull up Django model data based on ALREADY filled out form fields for other ForeignKeys
I have a form in which there are several fields with foreign keys. For example, the table "Entrance" (3 entries -> 1st entrance, 2nd entrance, 3rd entrance), "Apartment" (30 ...
0
votes
1
answer
409
views
Laravel 10 + Filament v3 error Call to a member function getForeignKeyName() on null
I dont know why it's not working and I don't know where or what to look for honestly. I have the main table access_permits
structure
id
permit_id
type
user_relationship_id
vehicle_relationship_id
...
-3
votes
1
answer
112
views
define foreign keys converting an ER Diagram into tables in SQL
I am converting an ER Diagram I did into tables in SQL.
How do I define my foreign keys?
I tried two ways but the one where I am referencing does not run and the other doesn't work.
create table ...
-1
votes
1
answer
75
views
get unprocessed rows that have no association in processed table
How do I get unprocessed rows that have no association in Processed_Table with the least number of queries (SQLite 3)?
Nested queries will work fine.
Main_Table columns: Id
Processed_Table columns: ...
1
vote
1
answer
115
views
How to change a default setting temporarily in PostgreSQL?
In my psql script all foreign key references include the clause on delete cascade on update cascade, because the default is on delete no action on update no action:
create table x (
y bigint
...
2
votes
1
answer
180
views
Problem with partitioning and foreign keys
I encountered an issue while adding partitioning to Table1.
Previously, this table had a primary key consisting only of the Id column, but when I added partitioning, I had to include AddTimestamp in ...
3
votes
2
answers
143
views
PostgreSQL zero-or-one to zero-or-one relationship
As the title describes I want to have a zero-or-one to zero-or-one relationship.
For example, let's say we have two tables Calls and Files. A call might have an attached file on it, and vice versa. ...
1
vote
1
answer
192
views
Difference between a reference and foreign key in GORM
In the GORM documentation for reference and foreign key
https://gorm.io/docs/belongs_to.html
What does a foreign key do?
what does a reference do?
What is the difference between a foreign key and ...
2
votes
1
answer
160
views
Django GeneratedField as ForeignKey with referential integrity
I'm trying to create a generated field that is also a foreign key to another table, while maintaining referential integrity at the database level.
Basically, I'm trying to have the same effect as the ...
-2
votes
1
answer
49
views
Stuck at (erno: 150 "Foreign key constraint is incorrectly formed,") [duplicate]
I'm new to learning Laravel 11, and I'm stuck with the (erno: 150 "Foreign key constraint is incorrectly formed,") and despite trying various suggestions I’ve seen, I still can't resolve it. ...