music/models.py
from django.db import models
class Album(models.Model):
artist = models.CharField(max_length=50)
album_title = models.CharField(max_length=50)
genre = models.CharField(max_length=50)
album_logo = models.CharField(max_length=500)
class Song(models.Model):
album = models.ForeignKey(Album, on_delete=models.CASCADE)
file_type = models.CharField(max_length=50)
song_title = models.CharField(max_length=50)
-----------------------------------------------------
#sync model with databasepython manage.py migrate
#update model
python manage.py makemigrations music
music\migrations\0001_initial.py
- Create model Album
- Create model Song
python manage.py sqlmigrate music 0001
BEGIN;
--
-- Create model Album
--
CREATE TABLE "music_album" ("id" integer NOT NULL PRIMARY KEY AUTOINCREMENT, "artist" varchar(50) NOT NULL, "album_title
" varchar(50) NOT NULL, "genre" varchar(50) NOT NULL, "album_logo" varchar(500) NOT NULL);
--
-- Create model Song
--
CREATE TABLE "music_song" ("id" integer NOT NULL PRIMARY KEY AUTOINCREMENT, "file_type" varchar(50) NOT NULL, "song_titl
e" varchar(50) NOT NULL, "album_id" integer NOT NULL REFERENCES "music_album" ("id") DEFERRABLE INITIALLY DEFERRED);
CREATE INDEX "music_song_album_id_62a413c8" ON "music_song" ("album_id");
COMMIT;
python manage.py migrate
Operations to perform:
Apply all migrations: admin, auth, contenttypes, music, sessions
Running migrations:
Applying music.0001_initial… OK
No comments:
Post a Comment