user1086337
user1086337

Reputation: 397

Manage.py sqlall <myapp> does not create column

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.

Upvotes: 1

Views: 1569

Answers (2)

aneroid
aneroid

Reputation: 16057

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.

Upvotes: 1

Daniel Roseman
Daniel Roseman

Reputation: 600026

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.

Upvotes: 2

Related Questions