DEV Community

siddharth shukla
siddharth shukla

Posted on

How To Create Django Models

Create a model field within models.py file

class Contact(models.Model):
name = models.CharField(max_length=100)
email = models.EmailField(max_length=100)
subject = models.CharField(max_length=100)
message = models.TextField()
mobile = models.IntegerField(max_length=180)
created_on = models.DateTimeField(auto_now_add=True)
Associate with settings.py

INSTALLED_APPS = [
'contact.apps.ContactConfig',
]

Run migrations command

python manage.py makemigrations

Check Migration

python manage.py showmigrations
python manage.py migrate

https://www.youtube.com/watch?v=rugSoarfi58&t=6s

https://realprogrammer.in/how-to-create-django-models/

Top comments (1)

Collapse
 
codemouse92 profile image
Jason C. McDonald

We encourage the entire article to be published on DEV.to (if you have proper rights), with a linkback if appropriate. Otherwise, we recommend original material, such as an original commentary on the article. From the Terms of Use:

Users must make a good-faith effort to share content that is...not designed primarily for the purposes of promotion or creating backlinks. Additionally, posts must contain substantial content — they may not merely reference an external link that contains the full post.

Posts that are simply intended to encourage readers to view an external resource are discouraged.

Thank you.