1

I added orgname = models.CharField(max_length=50) to my an existing class in my models.py and I ran python manage.py syncdb but figured out that it doesn't create columns (I'm using PostgreSQL by the way), so I needed to do python manage.py sqlall <myapp> which I did and it outputted the following:

BEGIN;
CREATE TABLE "file_uploader_files" (
    "id" serial NOT NULL PRIMARY KEY,
    "file" varchar(100) NOT NULL,
    "orgname" varchar(50) NOT NULL
)
;
COMMIT;

Yet, when I go into the shell for Django or look in pgAdmin3, the column is still not created. What am I doing wrong? I'd add it manually but I'm not sure how.

P.S. The table was already created before hand and so was the file varchar, orgname came after I initial made that column.

user1086337
  • 387
  • 1
  • 7
  • 19

2 Answers2

2

The documentation for the sqlall command says:

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

It prints the SQL, it doesn't run anything. Django will never modify your schema, you'll need to do it yourself - the output above can help by showing you the type of the orgname field. Or use something like South.

Daniel Roseman
  • 588,541
  • 66
  • 880
  • 895
  • It's saying the column is already created in the table (in PgAdmin3 when I attempt to add the column myself) yet I can't find it anywhere and it doesn't show up in PgAdmin3. Thanks for the help by the way. – user1086337 Sep 18 '12 at 08:26
1

Also see this SO question: update django database to reflect changes in existing models (the top two answers cover your question).

From the accepted answer:

note: syncdb can't update your existing tables. Sometimes it's impossible to decide what to do automagicly - that's why south scripts are this great.

And in the other another answer...

python manage.py reset <your_app>

This will update the database tables for your app, but will completely destroy any data that existed in those tables.

Community
  • 1
  • 1
aneroid
  • 12,983
  • 3
  • 36
  • 66