MODELS IN DJANGO

MODELS.PY

# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models
# Create your models here.
from django.db import models
class Crawler(models.Model):#Model class name Crawler db name 
name = models.CharField(max_length=100)
value = models.DecimalField(max_digits=10,decimal_places=2)
location = models.CharField(max_length=100)
def __str__(self):
return self.name

A Model Is a Mapping to a Database Table
Open cmd go to ur project
 manage.py makemigrations
python manage.py migrate
We Can Preview the SQL in Our Migration
python manage.py sqlmigrate crawler 0003
Let’s Migrate Our Migration
python manage.py migrate






There’s an extra step called migrations thatneeds to happen only right after you create
a new model or update an existing model

The ORM translates Python code to SQL for us behind the scenes

Comments

Popular Posts