chuve
chuve

Reputation: 728

Django admin site not displaying new column after update model

I have one problem with Django Framework. I changed one model insert this:

masterweb_link = models.CharField(_('masterweb_link'), help_text=_('link to MasterWeb tour'), max_length=300, null = True, blank = True)

After that I was this: - python manage.py syncdb

and db_application was changed and now I can work with new column in admin panel. On my local-pc everything is fine when i tried to check it.

But, when I try to do this on host, after all my actions model modify and database too, but Django admin site not displaying new column.

I have no errors when i do all my actions! Please help.

Upvotes: 1

Views: 3506

Answers (4)

Snehal Parmar
Snehal Parmar

Reputation: 5851

If nothing works, try deleting the model in your models file and then syncdb and try using django evolution after that reset django_evolution and then syncdb after all this try again changing your models file run the steps again, I hope this will solve the problem, It worked in my case...

following are the steps :

1 change your models file to old.

  1. then run syncdb.

     ./manage.py syncdb
    
  2. then run evolve:

     ./manage.py evolve --hint
    
  3. execute evolve:

     ./manage.py evolve --hint -x
    
  4. reset django evolution:

     ./manage.py reset django_evolution
    
  5. run syncdb:

     ./manage.py syncdb
    

Now, change your models file for new model and run all the steps again.

I hope this will help you.

Upvotes: 1

Chris SH
Chris SH

Reputation: 1859

Also check your admin.py file, the second part of the Django tutorial has you hard-coding it.

Upvotes: 0

Andy
Andy

Reputation: 50640

As Daniel Roseman mentioned, syncdb does not modify existing tables.

To do this, you need to use south http://south.aeracode.org/

A very quick walk through for converting your existing application to use south. First, you can install it using easy_install by typing easy_install South. If you wish to install it from Mercurial or from a snapshot tar.gz, they have instructions provided here.

Once it is installed, you need to convert your existing application to use south. In your application's settings.py file, add south to INSTALLED_APPS and then rerun python manage.py syncdb. All this is doing is adding data tables for the south application. It is not doing anything with your model yet.

Now, you want to undo the change you made in your original post. Go back to what is was. We will be making that change in a few minutes, but first, we need to tell south what your application looks like now.

python manage.py convert_to_south <appname> Replace <appname> with your application's name. This is going to create the initial migration file for your application.

Commit these changes to your version control (or distribute the application via your normal process to your other developers). It should be a new folder named migrations in your application directory. You will need to commit/distribute all files that appear in this folder.

One time thing: Everywhere that your application is installed needs to run this command to convert to using south as well. python manage.py migrate <appname> 0001 --fake According to the documentation, this is required because the initial migration that convert_to_south makes will try and create all the existing tables; instead, you tell South that it’s already applied using --fake, so the next migrations apply correctly.

Now, we are going to make your change. Re-edit your model to make the change you want. Save the model.

Run this command: python manage.py schemamigration <appname> --auto. South will analyze your models and how they have changed and create a migration script. This is why we needed to revert your changes back to their original state. Otherwise, south wouldn't know what it from migrating from.

When it is complete, run python manage.py migrate <appname>. Again, commit or distribute the migrations folder. Each location this is deployed will need to run python manage.py migrate <appname>.

In the future when you make schema changes you will run python manage.py schemamigration <appname> --auto to create the migration script and python manage.py migrate <appname> to install the changes.

I also recommend glancing at the documentation for other things south is capable of handling during migrations. The above should get you started though. South's documentation is location here.

Upvotes: 1

Daniel Roseman
Daniel Roseman

Reputation: 600059

syncdb doesn't modify existing tables.

Upvotes: 3

Related Questions