Safari
Safari

Reputation: 11935

Django first app: error during the creation of sql tables from my models

I'm new in Python and I would to start some tutorial using Django.

I would use PyCharm as IDE.

So, I tried to create my start Django project.

I use a Mac, Python 2.7.5 version, Django 1.7.5 version.

I follow this tutorial to create my first Django app.

When I try to crate SQL Tables (in Pycharm I use this command: Alt + R, sql command and the name of my app example) I have this error:

bash -cl "/System/Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7 /Applications/PyCharm.app/Contents/helpers/pycharm/django_manage.py sql FirstExample /Users/Gianluigi/PycharmProjects/mycompany"
CommandError: App 'FirstExample' has migrations. Only the sqlmigrate and sqlflush commands can be used when an app has migrations.

Process finished with exit code 1

Upvotes: 0

Views: 188

Answers (3)

Aseem
Aseem

Reputation: 6779

https://www.jetbrains.com/pycharm/quickstart/django_guide.html

while following this link, in CREATING DATABASE section when it says use the magic Ctrl+Alt+R shortcut twice: we actually use it once and in console type makemigrations and then migrate

Upvotes: 0

heidi
heidi

Reputation: 665

You don't need to use sql command. Assuming you have your database information correctly set up in settings.py, your python manage.py ... will be able to do everything for you.

In this case you would do python manage.py makemigrations mycompany followed by python manage.py migrate.

Upvotes: 2

brunofitas
brunofitas

Reputation: 3083

Lets say we have an app users. Add that app to settings

models.py:

class User(Django_User):
    observations = CharField(max_length=2048, null=True, blank=True)

you should run the following command first to create the migrations:

python manage.py makemigrations

This will create your database tables

That's it!

https://docs.djangoproject.com/en/1.7/topics/migrations/

Upvotes: 1

Related Questions