Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django not create database table

Tags:

python

django

Hey, I've a database already created. Now I've updated UserProfile with:

class UserProfile(models.Model):
    user = models.ForeignKey(User, unique = True, related_name = 'user')
    follows = models.ManyToManyField("self", related_name = 'follows') <-- NEW LINE

so python manage.py sqlall myapp returns me:

[...]
CREATE TABLE "myapp_userprofile_follows" (
    "id" integer NOT NULL PRIMARY KEY,
    "from_userprofile_id" integer NOT NULL,
    "to_userprofile_id" integer NOT NULL,
    UNIQUE ("from_userprofile_id", "to_userprofile_id")
)
[...]

When I run python manage.py syncdb:

Creating tables ...
Installing custom SQL ...
Installing indexes ...
No fixtures found.

But the table is not created when I try to insert data into. Why? (I'm testing locally, with sqlite3)

like image 761
Fred Collins Avatar asked Jun 01 '11 22:06

Fred Collins


2 Answers

have you added your app to INSTALLED_APPS in settings.pys:

settings.py

INSTALLED_APPS = (
    ... ,
    'my_app',
)

https://docs.djangoproject.com/en/dev/ref/settings/?from=olddocs#installed-apps

like image 31
Timmy O'Mahony Avatar answered Oct 28 '22 03:10

Timmy O'Mahony


manage.py syncdb will not modify existing tables to add or remove fields. You will need to either manually modify your database, or use a tool like South to create automated database migrations (which is what I highly recommend)

like image 173
bradley.ayers Avatar answered Oct 28 '22 03:10

bradley.ayers