7

I am trying to learn about python-django. I want to make self app named books.

When I ran this command

$ python manage.py sqlall books

Following error arises

CommandError: App 'books' has migrations. Only the sqlmigrate and sqlflush commands can be used when an app has migrations.

I did not understand why this error arise and what does it mean? Any help would be appreciated. Thanks

rishi kant
  • 1,235
  • 1
  • 9
  • 28

2 Answers2

0

After typing python manage.py sqlall --help I get the following:

Prints the CREATE TABLE, custom SQL and CREATE INDEX SQL statements for the given model module name(s).

It prints the SQL that is used to create these tables. As they already exists, Django doesn't print them and instructs to use sqlmigrate (print SQL for a specific migration) or sqlflush (print SQL which returns tables to their initial state).

jacekbj
  • 631
  • 3
  • 10
0

From django documentation of sqlall

django-admin.py sqlall

Prints the CREATE TABLE and initial-data SQL statements for the given app name(s).

In later versions of django starting from 1.7, you can do the same with this:

python manage.py sqlmigrate appname migration_name

As you are following along the django tutorial, for your case this will be

python manage.py sqlmigrate books 0001

This worked for me in django 1.8. You can read more from the documentation of sqlmigrate

django-admin sqlmigrate

Prints the SQL for the named migration. This requires an active database connection, which it will use to resolve constraint names; this means you must generate the SQL against a copy of the database you wish to later apply it on.

Sнаđошƒаӽ
  • 16,753
  • 12
  • 73
  • 90