Talal Alsarrani
Talal Alsarrani

Reputation: 25

How to use a migration tool in Django 1.6 and sqlite 2.8?

I'm new to Django and databases in general. I made a new app and than added a class to its model. After that I added another thing to my class, and I ran this command "python3.2 manage.py sql todo". and I got this

CREATE TABLE "todo_item" (
"id" integer NOT NULL PRIMARY KEY,
"description" text NOT NULL,
"dueDate" date NOT NULL,
"status" varchar(20) NOT NULL
);
COMMIT;

I thought that will do it, but I still get this error:

Exception Value: no such column: todo_item.status

status is the new thing that I want to add to my item class.

Upvotes: 0

Views: 814

Answers (1)

catavaran
catavaran

Reputation: 45575

manage.py sql todo just prints the SQL to create the table. This SQL is not executed against the db.

To create the table you should run manage.py syncdb.

But I suggest you to use the South app which provides the real migrations.

UPDATE: To add the new column to the existing empty table run the following command:

echo "ALTER TABLE todo_item ADD COLUMN status VARCHAR(20) NOT NULL;" | python manage.py dbshell

If the table is not empty and you can't delete the data from it then you have to set the default value for that column:

echo "ALTER TABLE todo_item ADD COLUMN status VARCHAR(20) NOT NULL DEFAULT 'new';" | python manage.py dbshell

Upvotes: 4

Related Questions