program story

남쪽 마이그레이션이 작동하지 않는 이유는 무엇입니까?

inputbox 2020. 10. 9. 11:11
반응형

남쪽 마이그레이션이 작동하지 않는 이유는 무엇입니까?


먼저 데이터베이스를 만듭니다.

create database mydb;

설치된 Apps에 "south"를 추가합니다. 그런 다음이 자습서로 이동합니다. http://south.aeracode.org/docs/tutorial/part1.html

이 튜토리얼은 다음과 같이 지시합니다.

$ py manage.py  schemamigration wall --initial
>>> Created 0001_initial.py. You can now apply this migration with: ./manage.py migrate wall

좋습니다. 이제 마이그레이션합니다.

$ py manage.py migrate wall

하지만이 오류가 발생합니다 ...

django.db.utils.DatabaseError: (1146, "Table 'fable.south_migrationhistory' doesn't exist")

내가 구글 사용 그래서 (. 작동하지 따라서 내 870 질문에 유래에 요청), 나는이 페이지를 얻을 : http://groups.google.com/group/south-users/browse_thread/thread/d4c83f821dd2ca1c

좋아, 그래서 나는 그 지시를 따른다

>> Drop database mydb;
>> Create database mydb;
$ rm -rf ./wall/migrations
$ py manage.py syncdb

하지만 syncdb를 실행하면 Django는 많은 테이블을 생성합니다. 예, south_migrationhistory 테이블 을 생성 하지만 내 앱의 테이블도 생성합니다.

Synced:
 > django.contrib.admin
 > django.contrib.auth
 > django.contrib.contenttypes
 > django.contrib.sessions
 > django.contrib.sites
 > django.contrib.messages
 > south
 > fable.notification
 > pagination
 > timezones
 > fable.wall
 > mediasync
 > staticfiles
 > debug_toolbar

Not synced (use migrations):
 - 
(use ./manage.py migrate to migrate these)

멋지다 .... 이제 이것들을 마이그레이션하라고 알려줍니다. 그래서 이렇게합니다.

$ py manage.py  migrate wall
The app 'wall' does not appear to use migrations.

좋아, 좋아. 초기 마이그레이션에 벽을 추가하겠습니다.

$ py manage.py schemamigration wall --initial

그런 다음 마이그레이션합니다.

$ py manage.py migrate wall

그거 알아? 이 BS를 제공합니다.

_mysql_exceptions.OperationalError: (1050, "Table 'wall_content' already exists")

죄송합니다. 정말 짜증이납니다. 누군가 도울 수 있습니까? 감사.

South가 모든 작업과 올바르게 동기화되도록하려면 어떻게해야합니까? 내가 생각할 수있는 유일한 것은 INSTALLED_APPS에서 내 앱을 제거한 다음 syncdb를 실행 한 다음 다시 추가하는 것입니다.

정말 SILLY입니다.


South를 사용하면 새 앱으로 처음 시작할 때 테이블이 아직 데이터베이스에 추가되지 않은 경우 마이그레이션을 만들 수있을뿐만 아니라 데이터베이스에 이미 테이블이있는 레거시 앱에 대한 마이그레이션을 만들 수 있습니다. 핵심은 언제 무엇을해야하는지 아는 것입니다.

첫 번째 실수는 마이그레이션을 삭제 한 다음 syncdb를 실행했을 때입니다. Django는 더 이상 해당 앱을 남쪽에서 관리하기를 원한다는 사실을 몰랐기 때문에 테이블을 만들었습니다. 초기 마이그레이션을 만든 다음 마이그레이션을 실행했을 때 south는 django가 이미 만든 테이블을 만들려고 시도했기 때문에 오류가 발생했습니다.

이 시점에서 두 가지 옵션이 있습니다.

  1. 데이터베이스에서 벽 앱의 테이블을 삭제 한 다음 $ py manage.py migrate wall실행하면 마이그레이션이 실행되고 테이블이 생성됩니다.

  2. 초기 마이그레이션 실행 가짜 $ py manage.py migrate wall 0001 --fake이렇게하면 South에 이미 데이터베이스에 테이블이 있다는 것을 알려줄 것이므로 가짜로하면 south_migrationhistory 테이블에 행이 추가되므로 다음에 마이그레이션을 실행할 때 첫 번째 마이그레이션을 알 수 있습니다. 이미 실행되었습니다.

데이터베이스없이 새로운 프로젝트 설정

  1. 데이터베이스 생성
  2. 설치된 앱에 남쪽 추가
  3. syncdb를 실행하면 django 및 south 테이블이 데이터베이스에 추가됩니다.
  4. 앱 추가
  5. 각 앱 실행에 대해 앱 python manage.py schemamigration app_name --initial의 초기 마이그레이션 파일이 생성됩니다.
  6. 그런 다음 south migrate를 실행 python manage.py migrate app_name하면 데이터베이스에 테이블이 추가됩니다.

레거시 프로젝트 및 데이터베이스 설정

  1. 설치된 앱에 남쪽 추가
  2. syncdb를 실행하면 데이터베이스에 south 테이블이 추가됩니다.
  3. 실행되는 각 앱에 대해 python manage.py schemamigration app_name --initial초기 마이그레이션이 생성됩니다.
  4. 각 앱 실행 python manage.py migrate app_name 0001 --fake에 대해 이것은 남쪽으로 가짜로 만들어지고 해당 모델의 데이터베이스에 아무 작업도 수행하지 않으며 south_migrationhistory 테이블에 레코드를 추가하기 만하면 다음에 마이그레이션을 생성 할 때 모두 가능합니다. 세트.

데이터베이스없이 레거시 프로젝트 설정

  1. create database
  2. add south to installed apps
  3. for each of your apps run python manage.py schemamigration app_name --initial This will create your initial migrations
  4. run syncdb, this will add any apps that don't have migrations to the database.
  5. then run south migrate python manage.py migrate this will run all migrations for your apps.

Now that you are setup with south, you can start using south to manage model changes to those apps. The most common command to run is python manage.py schemamigration app_name migration_name --auto that will look at the last migration you ran and it will find the changes and build out a migration file for you. Then you just need to run python manage.py migrate and it alter your database for you.

Hope that helps.


This is how I get things working.

pip install South

# add 'south', to INSTALL_APPS, then
python manage.py syncdb

# For existing project + database
python manage.py convert_to_south app_name

# Thereafter, call them per model changes
python manage.py schemamigration app_name --auto
python manage.py migrate app_name

References:

http://garmoncheg.blogspot.com/2011/08/django-how-and-why-to-use-migrations.html http://www.djangopro.com/2011/01/django-database-migration-tool-south-explained/


The tutorial you're using states:

(If this fails complaining that south_migrationhistory does not exist, you forgot to run syncdb after you installed South.)

Assuming that your post accurately details the steps you've taken, following that link seems to show that you missed a step before setting up your new app. As you are following a tutorial for setting up migrations on a new application, the order is:

  1. Add south to INSTALLED_APPS.
  2. Run syncdb.
  3. Then follow the tutorial.

I.e., you should've already run syncdb before you added in the models for your new app. Your solution of removing your app from INSTALLED_APPS should work, but it's worth noting that it's really only a "silly" work-around, as you missed a step earlier on. Had syncdb been run before you created the models for that app, you wouldn't have to use the work-around.


Just for future ref. If South is giving you any problems:

  1. Remove the migrations directories from your app directories
  2. Delete South_migrations from your database
  3. Run manage.py syncdb
  4. Go back to using South (e.g. './manage.py convert_to_south something, ./manage.py migrate ...')

This seems obvious, but I'd highly recommend reading the docs.

Even after reading the answers to this question I struggled to understand how to use South effectively.

That all changed of course the day I read the docs and you should too, South is simpler to use than you might think.

http://south.aeracode.org/docs/about.html

http://south.aeracode.org/docs/tutorial/index.html

http://south.aeracode.org/docs/convertinganapp.html#converting-an-app

I also found this useful:

http://www.djangopro.com/2011/01/django-database-migration-tool-south-explained/

And make sure you read Jeff Atwood's Coding Horror articles on database version control.


How do I get South to work and sync correctly with everything? The only thing I can think of is remove my app from INSTALLED_APPS, then run syncdb, then add it back on.

I have used that fix with South troubles in the past. Not a pretty solution but very effective ;)

But the main problem is that your order isn't correct. You should have run syncdb before the tutorial. Than it works properly.

참고URL : https://stackoverflow.com/questions/4840102/why-dont-my-south-migrations-work

반응형