SQLarchemy implement foreign key constraint and four kinds explaining

First, the table relationships:

            There are three relationships between tables: one to one, one to many, many to many, but SQLARCHMY in orm can also simulate these three relationships.

            In fact, because one of the underlying SQLarchemy is by way of an analog-to-many, so many relationships at the first look.

Foreign key:

            Use SQLarchemy create a foreign key is very simple, add a field from the table, specify the field of the foreign key of which word on it from the table of the foreign key fields from the table of the foreign key, the primary table must be the primary key field type consistent.

Second, the foreign key constraint have the following:

1.restrict: If the child has a parent table table associated data corresponding to the parent table deletes the corresponding data, prevent deleted, the default entry

2.no action: in mysql, with restrict.

3.cascade: cascade operation

4.set null: the parent table deletes the corresponding data, the child table corresponding to the data item is set to null

 

Example: to-many relationship

           

Guess you like

Origin www.cnblogs.com/yingxiongguixing/p/12048360.html