0

I have problems, I don't know how to update database...

So here is my problem: I updated my app models.py with one line *yrs = models.CharField(max_length=4)*:

from django.db import models

class Books(models.Model):
    title = models.CharField(max_length=150)
    author = models.CharField(max_length=100)
    *yrs = models.CharField(max_length=4)*
    read = models.CharField(max_length=3)

    def __str__(self):
        return self.title + " / " + self.author + " / " + **self.yrs** + " / " + self.read + " "

So, but now I get error:

Exception Type: DatabaseError
Exception Value:    no such column: books_books.yrs

So, do you know how I can fix it? Thank you ;)

1
  • 1
    Use South Migration tool and do a migration for your database. Following the tutorial will give you exactly what you want. Commented Sep 11, 2013 at 6:24

1 Answer 1

2

You can use South to migrate your data. If you don't care about your existing data, just remove your database file (in case of sqlite3), and run python manage syncdb again

South is pretty easy to use and the tutorial is giving you a lot of real examples.

If South doesnt sound appealing to you, you can also alter directly your table using dbshell

python manage.py dbshell
ALTER TABLE <appname_modelname> ADD COLUMN <column_type> DEFAULT '';
Sign up to request clarification or add additional context in comments.

4 Comments

+1: Also if he doesn't care about data he can do python manage.py sqlclear MyApp before syncdb instead of manually finding and removing the table.
Does sql clear avoid to have to create a super user and so on, as syncdb does?
sqlclear drops all tables defined in MyApp. It does not create anything.
Correction. Actually it only prints drop statements. It should be used like that python manage.py sqlclear MyApp | python manage.py dbshell (at least under Linux).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.