skip to Main Content

When I do the migration, I get the following message in the terminal:

Migrations for ‘bookList’:
bookList/migrations/0001_initial.py:
Create model bookList

And then I run the migrate command:

Operations to perform:

Apply all migrations: admin, auth, bookList, contenttypes, sessions

When I look at mysql, a table named books does not appear.
I’ve included the contents of my models.py file below:

from django.db import models

# Create your models here.
class BookList(models.Model):
    site_name = models.TextField()
    site_id = models.TextField()
    image = models.TextField()
    book = models.TextField()
    author = models.TextField()
    publisher = models.TextField()
    price = models.TextField()
    link = models.TextField()
    category_name = models.TextField()
    category_id = models.TextField()
    class Meta:                                                                                                                                                        
        managed = False
        db_table = 'books'

The contents of my 0001_initial.py file are as follows:

# Generated by Django 4.1.1 on 2022-09-26 13:17

from django.db import migrations, models


class Migration(migrations.Migration):

    initial = True

    dependencies = [
    ]

    operations = [
        migrations.CreateModel(
            name='BookList',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('site_name', models.TextField()),
                ('site_id', models.TextField()),
                ('image', models.TextField()),
                ('book', models.TextField()),
                ('author', models.TextField()),
                ('publisher', models.TextField()),
                ('price', models.TextField()),
                ('link', models.TextField()),
                ('category_name', models.TextField()),
                ('category_id', models.TextField()),
            ],
            options={
                'db_table': 'books',
                'managed': False,
            },
        ),
    ]

What do I need to do to be able to view my books table in mysql?

2

Answers


  1. You can try again without using this line managed = False in your code.

    Login or Signup to reply.
  2. According to documentation

    If False, no database table creation, modification, or deletion operations will be performed for this model. This is useful if the model represents an existing table or a database view that has been created by some other means. This is the only difference when managed=False.

    So the reason for why Django is not creating the table is because you’re telling it not to manage the tables for that model. Just change in Meta, managed to True, or simply remove it.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search