Django 3: Create a simple Model

from django.db import models

class Country(models.Model):
    country_iso = models.CharField(max_length=2, primary_key=True)
    country_iso3 = models.CharField(max_length=3, unique=True )
    country_name = models.CharField(max_length=80)    # old country_print_name
    continent_code = models.CharField(max_length=2)


    class Meta:
        managed = True
        db_table = 'gc_country'
python3.6 manage.py makemigrations location
Migrations for 'location':
  location/migrations/0001_initial.py
    - Create model Country
python3.6 manage.py sqlmigrate location 0001
BEGIN;
--
-- Create model Country
--
CREATE TABLE "gc_country" ("country_iso" varchar(2) NOT NULL PRIMARY KEY, "country_iso3" varchar(3) NOT NULL UNIQUE, "country_name" varchar(80) NOT NULL, "continent_code" varchar(2) NOT NULL);
CREATE INDEX "gc_country_country_iso_104d061b_like" ON "gc_country" ("country_iso" varchar_pattern_ops);
CREATE INDEX "gc_country_country_iso3_86f72382_like" ON "gc_country" ("country_iso3" varchar_pattern_ops);
COMMIT;

Published: Dec. 12, 2019

Change Content

The information on this page is user generated content. The content does not claim to be complete or correct.

Everybody is invited to add or change the data. Just click on this link. No login or email is required. Thanks.