SQLite Visualization Tools and Django-south

Source: Internet
Author: User
Tags sqlite database

A way to visualize SQLite under a Linux system

One: Install Sqlitebrowser:

sudo apt-get install Sqlitebrowser

Two: At the terminal prompt, enter Sqlitebrowser to start the graphical interface:

The drawback of Django's SYNCDB command is that it does not synchronize the modification or deletion of the model to the database, thus causing a large inconvenience, let's introduce a tall tool south:

The first step is to install South.

The second step is to place South in the installed:

The third step syncdb, build South table, after success will be more than a table and give the following tips

At this point we create a new app ' Southtut ', written in models.py:

Typing command:./manage. PY schemamigration southtut --initial

Check shift+enter: input southtut --initial, terminal display

In this case, there is a folder under the app for archiving:

There are no knight tables in the SQLite database at this time, you need to merge

Enter app name such as Southtut, this is the end of the merge, this table appears in the database

If Knight is changed, for example

At this point enter the command:./manage. PY schemamigration southtut --auto

From the output prompts can be seen, South has added a new migration record file (0002_auto__add_field_knight_dances_whenever_able.py), South is named after the serial number + changes. Next, we use the Migrate command to modify the database as prompted:

The changes are saved to the database at this point.

Let's change it and add a column:

When you execute schemamigration again, there are some options that you have not seen:

Where option 1 means to abandon this automatic migration and exit, you can add the default value in field and then execute schemamigration. Option 2 means adding a one-time value to a row that already exists. When you select 2 o'clock, a python cue line appears, and you can use the Python datetime module:

At this point you can view the automatically generated migration record file, South will add a default value of 0 for the newly created column so that the database does not get an error. Then we can execute the migrate again.

If South is not used at the start of the project, we can enable it as follows:

One: Join SOUTH,SYNCDB to create the South_igratitonhistory table.

II: Python manage.py convert_to_south youappname Create migrations directory under the Youappname directory

Can be used normally later.

In addition South also provides backtracking function: Specify the app in migrate and backtrack py file: manage.py migrate southtut 0001_initial.py:

If the south in the process of synchronizing the database error, then the migrations directory corresponding to the change of the Python file will not be executed, you can run Python manage.py migrate--list View the py file is not executed, the file name is not preceded by * Indicates that the file corresponding changes do not respond to the database, just remove the problematic migrate, refer to the error prompt to modify the models resynchronization can, or directly change the corresponding py file repair errors

Deep Data Migration:

Data migration is used to change the data stored in your database to match a new pattern, or feature.

Http://www.cnblogs.com/BeginMan/p/3325897.html

Demo

http://blog.csdn.net/watsy/article/details/11965019

1) When creating a new project without a database

1. Create a database

2. Add South to Installed_apps

3. Run the SYNCDB command, which adds Django and South data tables to the database

4. Add the APPS you created to Installed_apps

5. Run "python manage.py schemamigration app_name--initial" For each app, which will create migration directories and corresponding files in each app's directory.

6. Then run "python manage.py migrate app_name", which adds the app's datasheet to the database

  2) Use South in a saved project with a database

1. Add South to Installed_apps

2, run SYNCDB, it joins South's data table to the database

3. Run Python manage.py schemamigration app_name--initial for each app, which will create migration directories and corresponding files in each app directory

4, each app runs "python manage.py migrate app_name 0001--fake", the command will not do anything to the database, just deceive south, let it in south_ Add some records to the Migrationhistory table to make sure everything is done the next time you want to create migration files.

  3. Use South in a saved project without a database

1) Create a database

2) Add South to Installed_apps

3) Run "python manage.py schemamigration app_name--initial" separately for each app, which will create migration directories and corresponding files in each app's directory

4) Run SYNCDB, which adds all apps without migrations to the database

5) then run the "python manage.py Migrate" command, which will run the migration operation for all of your apps.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.