![]() I really recommend you read the django docs which talk about the modeling of relationships and the various degrees of normalisation. Now this is a somewhat contrived answer, and I'm sure you could go further to improve this design, but hopefully it demonstrates the point. Now we won't be duplicating the reporters email address, as we can store this ONCE in the Reporter table, making it easier to update this value in the future. So we could start to improve on this and begin to normalise our model by defining two separate tables, which use a ForeignKey field to map the many-to-one relationship (aka that a reporter can publish many articles, but an article only has one reporter). This article explains database normalization and how to normalize a database through a hands-on example. The process aims to create a system that faithfully represents information and relationships without data loss or redundancy. This is a problem, as in the future if we want to update a reporters email address, we might a miss row and corrupt our data. In fact, whereas normalization itself is intuitive, it usually takes quite a bit of advanced skill to recognize when it is appropriate to de-normalize a. Database normalization is a method in relational database design which helps properly organize data tables. If we populate this model, we are going to have redundancy as soon as a reporter publishes more than one article, as we will be duplicating email information, storing the same email address in multiple rows. Headline = models.CharField(max_length=100) Reporter = models.CharField(max_length=30) You might design a model like this first off class Newspaper(models.Model): Normalization is the process of organizing a database to reduce redundancy and improve data integrity. Normal forms are used to eliminate or reduce redundancy in database tables. So, it helps to minimize the redundancy in relations. When we go through the normalization process, we increase the number of tables in the database, while decreasing the amount of data stored in each table. Redundancy in relation may cause insertion, deletion, and update anomalies. So using an example contrived from the django docs, say we work for a newspaper company and we want to keep track of each reporter and the articles they publish. Normalization is the process of minimizing redundancy from a relation or set of relations. In django this means that rather than have one model, you might have multiple smaller models, which represent the relationship between database tables via ForeignKey and ManyToMany fields provided by the Model API. Normalisation is not a Django or even Python concept - it is a wider approach to designing a relational database schema such that you remove duplication and eliminate redundancy.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |