Database
How to Ensure Concurrent Data Consistency in Django
· β˜• 2 min read
The first part mainly covers optimistic and pessimistic locking. Locking guarantees data consistency under concurrency at the database level. Understanding locks helps you understand concurrency solutions. The second part mainly covers how to guarantee data consistency in concurrent scenarios within Django. 1. About Locks 1.1 Optimistic Locking The starting point

Using utf8mb4 in Django to Support Emoji
· β˜• 3 min read
1. What Is utf8 In theory, utf8 uses 1-6 characters, In practice, the latest utf8 specification uses only one to four bytes, and can encode at most 21 bits, which is exactly enough to represent all 17 Unicode planes. 2. What Is utf8mb4 utf8mb4 is a superset of utf8. In theory, if you were using utf8 before and then change the charset to utf8mb4, it will not cause any problem when reading the existing utf8-encoded data.

Django Model and E-R Diagram
· β˜• 6 min read
As requirements are gradually confirmed, the system’s DB model is gradually confirmed as well. Sometimes you use a tool like MySQL Workbench to draw an E-R diagram and then generate MySQL database tables, and at that point you need to reverse-generate Django Models; other times you write the Django Models directly, but then you need to look at the E-R diagram.

Meta Options in Django Models
· β˜• 4 min read
Define metadata for a model through an inner class “class Meta”, like this: 1 2 3 4 class Foo(models.Model): bar = models.CharField(max_length=30) class Meta: #...... Model metadata means: any data that is not a field such as ordering options, admin options, and so on. Below are all the Meta options you might use.