D
D
dr sbtn2016-05-13 00:42:42
Django
dr sbtn, 2016-05-13 00:42:42

In what there can be a problem with a DB? Didn't create additional tables?

The database contains the following models:

class Musician(models.Model):
    id_musician = models.AutoField(primary_key=True)
    pseudonym = models.CharField(max_length=30)

class Genre(models.Model):
    id_genre = models.AutoField(primary_key=True)
    name_genre = models.CharField("genre's name", max_length=30)

class Song(models.Model):
    id_song = models.AutoField(primary_key=True)
    name_song = models.CharField("song's name", max_length=30)
    album = models.CharField(max_length=30)
    release_date = models.DateField
    text = models.TextField
    musician = models.ManyToManyField(Musician)
    genre = models.ManyToManyField(Genre)

I'm working on the Django administration page. Filled in some data for artists and genres. When I try to add a song, I get an error. acace70e3e6c4972baa89093e7316f12.JPG
aa10c6ce12a9460a80d4c387faf652d0.JPG
Probably a stupid mistake due to the disgusting knowledge of the database, but nevertheless, tell me, what is my trouble?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
Anatoly Scherbakov, 2016-05-13
@dawasaturday

Let me sum up a few answers and add a little of my own.
- release_date = models.DateField()- brackets are missing, and also in some similar fields. I also suspect that it should blank=True, null=True.
- Explicit setting of primary keys is not necessary. id_song, id_genre, ...- superfluous. Django itself creates a named primary key idfor each table.
- It seems to me that many of your fields should have blank=True, otherwise they are all mandatory.
- Albumas it seems to me, it should be a separate table linked by foreign key.
After fixing this, makemigrations and migrate should be done as mentioned above.

A
asd111, 2016-05-13
@asd111

To create the necessary tables from models, migrations are used, which can be created and applied with the following commands:

manage.py makemigrations
manage.py migrate

D
Denis Arkhipov, 2016-05-13
@alphabear

Directly: there is no such table "JustLyrics_song_musician"

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question