foreign-keys

What's the right HTTP status code for a response when I can't perform a DELETE due to a FK constrain?

懵懂的女人 提交于 2019-12-12 09:29:18
问题 What would be the right response I should give to the users when they try to DELETE an entity on a datasource sitting behind a rest/odata api, and the operation cannot be performed due to a foreign key constrain? Is it a bad request? A not acceptable? A server-side error (>=500)? 回答1: Just found this website that says that '409 Conflict' should be used when 'the request could not be completed due to a conflict with the current state of the resource' and 'where it is expected that the user

How to set up a table with a recursive foreign key and a relationship declaratively in SQLAlchemy?

南楼画角 提交于 2019-12-12 09:27:35
问题 Suppose I have a table "nodes" where I store a tree. Each node has a primary key id and a column parent_id. Of course, I want to access a parent attribute of each node instance, that is, a relation. One might try: import sqlalchemy, sqlalchemy.orm, sqlalchemy.ext.declarative engine = sqlalchemy.create_engine('sqlite:///PATHTOMYDATABASE', echo=True) Base = sqlalchemy.ext.declarative.declarative_base() class Node(Base): __tablename__ = "nodes" id = sqlalchemy.Column(sqlalchemy.Integer, primary

Posting data to create related Tastypie resources simultaneously?

岁酱吖の 提交于 2019-12-12 09:19:06
问题 Given two related Django models A and B in a OneToMany relationship: models.py class A(models.Model): name = models.CharField(max_length=5) class B(models.Model): name = models.CharField(max_length=5) a = models.ForeignKey(A) And given (potentially non-optimal) Tastypie resources: api.py class AResource(ModelResource): bs = fields.ToManyField( 'projectname.api.BResource', 'bs', full = True) class Meta: queryset = A.objects.all() class BResource(ModelResource): a = fields.ToOneField( AResource

Remove Foreign Key Relationships From All Tables

*爱你&永不变心* 提交于 2019-12-12 08:47:37
问题 I have a database that has several tables. Many of the tables have fields with foreign key constraints. I want to truncate the tables and then repopulate them with new data, and I also want to take off the foreign keys, as some of the relationships have changed. basically, I want to build the FK constraints up from scratch again. How can I remove the current FK constraints from all tables? 回答1: You can play with the information_schema. Take a look at this page http://dev.mysql.com/doc/refman

Django - Foreign Key to User model

若如初见. 提交于 2019-12-12 07:46:22
问题 I want to create new model, something like: user_name = models.ForeignKey(u"Username", User), but when I try to syncdb, I get this error message: "AttributeError: 'unicode' object has no attribute '_meta'" When I look on some tutorials, everything seems to be the same like in my model and problem with "_meta" is never mentioned. 回答1: A safer way to do this is to use the AUTH_USER_MODEL from the settings file. Example: from django.db import models from django.conf import settings class Article

Databases: Making a Log of actions, how to handle various references?

馋奶兔 提交于 2019-12-12 07:38:26
问题 hope you all had a happy new year. So, my question is, what's the best way to make a log of actions. Let me explain it with a example, suppose we have these entities: User Friend (User is a friend of another User, many to many relationship) Message (An user can message another user) Group (An user can be in various groups) Game (A game can be played with various players, has some info like date of the game. this results in two tales, games and games_users, the latter stores a relationship

MySQL - Cannot add or update a child row: a foreign key constraint fails

ε祈祈猫儿з 提交于 2019-12-12 07:25:01
问题 This seems to be a common error, but for the life of me I can't figure this out. I have a set of InnoDB user tables in MySQL that are tied together via foreign key; the parent user table, and a set of child tables that store email addresses, actions, etc. These are all tied to the parent user table by a foreign key, uid , with all of the parent and child keys being int(10) . All of the child tables have a uid value with a foreign key constraint pointing to user.uid , and set to ON DELETE

Why to use foreign keys with no action on delete or update

元气小坏坏 提交于 2019-12-12 07:14:52
问题 I have a question of interest: I have 2 tables in mysql with InnoDb . table tbl_a has a primary key, named a_id ; table tbl_b has a primary b_id and a foreign key on tbl_a.a_id with " ON DELETE NO ACTION ". +-------------+---------------+---------------+ | Table Name | Primary Key | Foreign Key | +-------------+---------------+---------------+ | tbl_a | a_id | | | tbl_b | b_id | a_id | +-------------+---------------+---------------+ why should I still use InnoDb and foreign keys, if i don't

Cannot create a foreign key becaue it is in conflict with itself

旧城冷巷雨未停 提交于 2019-12-12 05:49:20
问题 I am trying to add a Foreignkey to a table and i cannot because i get this error: Msg 547, Level 16, State 0, Line 1 The ALTER TABLE statement conflicted with the FOREIGN KEY constraint "FK_RDATA_COMBO_VALUES_ID_REFERENCES". The conflict occurred in database "MyDatabase", table "dbo.EVA_REFERENCES", column 'ID_REFERENCES'. The error message says that the problem is a conflict with FK_RDATA_COMBO_VALUES_ID_REFERENCES but this is the name of the FK i am trying to create, it does not exist yet.

Multiple Primary Keys as single foreign key

旧街凉风 提交于 2019-12-12 05:10:09
问题 I have a requirement to design 2 or more tables. 1. SubParts table 2. MainParts table. A single MainPart can have multiple subparts. I am thinking of doing something like SubPart table: Id and Name MainPart table: Id and Name SubPart_MainPart relationship table: MainPart_ID SubPart_Ids(array or comma seperated) Is there a way to put multiple subpart_id in single column in the relationship table? or should I use MainPart_D and SUbPart_ID as combined primary key in the relationship id? the