foreign-keys Questions

4

I created a schema in MySQL 8.0 named hr. I'm creating two tables: one is locations and the other one departments, which has a foreign key referencing the table locations. create table hr.locations...
Boreas asked 14/11, 2021 at 6:50

27

Solved

Is there a nice easy way to drop all tables from a MySQL database, ignoring any foreign key constraints that may be in there?
Adjunct asked 13/8, 2010 at 12:28

5

Solved

I'm dynamically storing information in the database depending on the request: // table, id and column are provided by the request table_obj = getattr(models, table) record = table_obj.objects.get(...
Outbalance asked 9/4, 2010 at 14:1

6

Solved

How do I specify ON DELETE NO ACTION Foreign Key Constraint in my model designs? At present, I have: public class Status { [Required] public int StatusId { get; set; } [Required] [DisplayNam...
Melanite asked 13/10, 2012 at 0:41

2

Solved

In my PostgreSQL database I have the following tables (simplified): CREATE TABLE quotations ( receipt_id bigint NOT NULL PRIMARY KEY ); CREATE TABLE order_confirmations ( receipt_id bigint NOT N...
Bougie asked 27/4, 2014 at 16:23

4

Solved

I have to work with hibernate and not very sure how solve this problem, I've 2 table with a 1..n relationship like this: ------- TABLE_A ------- first_id (pk) second_id (pk) [other fields] ----...
Hypodermic asked 22/8, 2011 at 11:18

3

We have a database with a couple hundred tables. Tables using foreign_keys use INNODB. Sometimes we transfer data (individual tables using mysqldump) between our development, stage, and production...
Nitpicking asked 10/8, 2012 at 18:12

4

Solved

I would like to add a constraint that will check values from related table. I have 3 tables: CREATE TABLE somethink_usr_rel ( user_id BIGINT NOT NULL, stomethink_id BIGINT NOT NULL ); CREATE T...

1

Solved

I have two models Product and Cart. Product model has maximum_order_quantity. While updating quantity in cart, I'll have to check whether quantity is greater than maximum_order_quantityat database ...

3

Solved

Is there a way to set foreign key relationship using the integer id of a model? This would be for optimization purposes. For example, suppose I have an Employee model: class Employee(models.Model...
Ashelyashen asked 17/5, 2010 at 0:9

2

Solved

Answer: Use db.Exec("PRAGMA foreign_keys = ON") to enforce foreign key constraint checks. Thanks @outdead When I update my SQLite database using GORM, foreign key constraints aren't enfor...
Deneb asked 1/12, 2021 at 21:47

4

Solved

I have several Customers who book Appointments. Each Appointment has exactly one customer, though a customer can be booked for multiple appointments occurring at different times. class Customer(mo...
Matejka asked 21/6, 2011 at 1:2

8

Solved

I am using MySQL and I have a table with an index that is used as a foreign key in many other tables. I want to change the data type of the index (from signed to unsigned integer) , what is the bes...
Tremble asked 6/5, 2009 at 14:37

14

Solved

I have the following table: CREATE TABLE child( id INTEGER PRIMARY KEY, parent_id INTEGER, description TEXT); How do I add a foreign key constraint on parent_id? Assume foreign keys are en...
Lurid asked 10/12, 2009 at 23:22

4

I've set up two tables: CREATE TABLE A ( id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, name TEXT ); CREATE TABLE B ( id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, id2 INTEGER, book TEXT, ...
Butchery asked 15/3, 2013 at 23:52

2

Solved

Trying to assign foreign key but when you run migrate, I get this this error, I do not understand what the problem is. SQLSTATE[HY000]: General error: 1215 Cannot add foreign key constraint (SQL: ...
Whirlpool asked 24/2, 2022 at 12:15

5

I have 60 tables. I want to drop 10 tables where these 10 tables are Constraints(PK,FK) to other 20 tables. While dropping these 10 tables, I need to truncate or delete data from the other 20 table...

2

symbol.py class Symbol(BaseModel): name = models.CharField(max_length=30,) class Meta: abstract = True class StockSymbol(Symbol): market = models.CharField(max_length=10,) my_daily_price = ...
Indomitability asked 4/2, 2018 at 6:53

12

Solved

In Oracle SQL Developer, if I'm viewing the information on a table, I can view the constraints, which let me see the foreign keys (and thus which tables are referenced by this table), and I can vie...
Winniewinnifred asked 17/7, 2009 at 14:46

10

Solved

I want to make a function that, given the name of a table, returns the model with that tablename. Eg: class Model(Base): __tablename__ = 'table' ...a bunch of Columns def getModelFromTableName(...
Revisionist asked 26/7, 2012 at 11:32

3

In MS SQL Server it is possible to create a foreign key with ON UPDATE CASCADE option, so whenever you update one of the columns in the primary key, the foreign keys in other tables will also be up...
Incombustible asked 17/8, 2009 at 19:20

2

Solved

I have 2 tables as you will see in my PosgreSQL code below. The first table students has 2 columns, one for student_name and the other student_id which is the Primary Key. In my second table called...
Be asked 17/2, 2015 at 9:44

8

Solved

A user has many uploads. I want to add a column to the uploads table that references the user. What should the migration look like? Here is what I have. I'm not sure if I should use (1) :user_id,...

2

create table users (id int not null auto_increment , username varchar(255) NOT NULL , password varchar(255) NOT NULL , active int NOT NULL , PRIMARY KEY (id)) ENGINE=InnoDB COLLATE=utf8_unicode_ci;...
Spinks asked 8/6, 2014 at 13:43

3

Solved

I'm trying to achieve something apparently simple but I couldn't find any answer, neither on Google nor here. I have a Django model, something dead-simple: class Shipment(models.Model): id = mode...
Petropavlovsk asked 7/2, 2012 at 9:48

© 2022 - 2024 — McMap. All rights reserved.