2015-09-01 10 views
5

मैंने models.py में मेरी एक तालिका में कुछ बदलाव किए हैं और इसे 'python manage.py माइग्रेट' के साथ माइग्रेट करने का प्रयास किया है और इसमें घंटों लग रहे हैं । मैंने केवल तीन फ़ील्ड (कॉलम) नामों के नाम बदल दिए हैं, और यह अब 2 घंटे से अधिक समय तक चल रहा है। यह मिनटों के मामले में आसानी से चला गया (मुझे लगता है) जब मैंने आज सुबह टेबल बनाया था। मौसम का प्रारंभ वह मॉडल है जहां परिवर्तन किए गए थे।django: 'python manage.py माइग्रेट' लेने का समय (और अन्य अजीब व्यवहार)

यहाँ models.py से क्या अब की तरह लग रहा है:

from django.db import models 
from django.contrib.gis.db import models as gismodels 
# from django.contrib.gis import admin 

# Create your models here. 

class Location(models.Model): # table name automatically chirps_location 
    locationID = models.IntegerField(default=0, primary_key=True) 
    lat = models.FloatField(default=0.0) 
    lon = models.FloatField(default=0.0) 
    geom = gismodels.PointField(null=True) 
    objects = gismodels.GeoManager() 
    def __unicode__(self): 
     return u"LocationID: " + unicode(self.locationID) 

# admin.site.unregister(Location) 
# admin.site.register(Location, admin.OSMGeoAdmin) 


class Rainfall(models.Model): 
    location = models.ForeignKey(Location) 
    year = models.IntegerField(default=0) 
    pentad_num = models.IntegerField(default=0)   
    pentad_val = models.FloatField(default=0.0) 

    class Meta: 
     ordering = ['location', 'year', 'pentad_num'] 

    def __unicode__(self): 
     return u"LocationID: " + unicode(self.location.locationID) + u" Year: " + unicode(self.year) + u" Pentad: " + unicode(self.pentad_num) 


class Start_of_Season(models.Model): 
    location = models.ForeignKey(Location) 
    crop = models.CharField(default='', max_length=40) 
    year = models.IntegerField(default=0) 
    first_rain = models.IntegerField(default=0) 
    onset_rain = models.IntegerField(default=0) 
    start_season = models.IntegerField(default=0) 

    class Meta: 
     ordering = ['location', 'crop', 'year']  

    def __unicode__(self): 
     return u"LocationID: " + unicode(self.location.locationID) + u" Year: " + unicode(self.year) + u" Start of Season pentad: " + unicode(self.start_season) 

वहाँ भी था कुछ अजीब व्यवहार है कि मैं समझाता इस से पहले चल रहा नहीं कर सकता है, तो मैं के सभी का एक संक्षिप्त ठहरनेवाला दे देंगे वह भी अगर यह सब संबंधित है।

सबसे पहले, मेरी Start_of_Season वर्ग इस तरह देखा (नोटिस फर्क सिर्फ इतना है कि पिछले 3 क्षेत्रों के नाम है):

class Start_of_Season(models.Model): 
    location = models.ForeignKey(Location) 
    crop = models.CharField(default='', max_length=40) 
    year = models.IntegerField(default=0) 
    first_rain_pentad = models.IntegerField(default=0) 
    onset_rain_pentad = models.IntegerField(default=0) 
    start_season_pentad = models.IntegerField(default=0) 

    class Meta: 
     ordering = ['location', 'crop', 'year']  

    def __unicode__(self): 
     return u"LocationID: " + unicode(self.location.locationID) + u" Year: " + unicode(self.year) + u" Start of Season pentad: " + unicode(self.start_season) 

के साथ प्रवास के:

python manage.py makemigrations 
python manage.py migrate 

सुचारू रूप से चलाने के लिए दिखाई दिया ।

लेकिन जब मैं एक अजगर स्क्रिप्ट (अंश) इस नव निर्मित Start_of_Season तालिका में पंक्तियां जोड़ने के लिए भाग गया:

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "access.settings") 
from chirps.models import Location, Rainfall, Start_of_Season 
django.setup() 

try: 
    with transaction.atomic(): 
     for loc in Location.objects.all(): 
      locID = loc.locationID 
      for yr in range(1981, 2014): 
       # some computations to find: c1, c2, c3 
       start_of_season = Start_of_Season() 
       start_of_season.location = Location.objects.get(locationID = locID) 
       start_of_season.crop = 'millet' 
       start_of_season.year = yr 
       start_of_season.first_rain_pentad = c1 
       start_of_season.onset_rain_pentad = c2 
       start_of_season.start_season_pentad = c3 
       start_of_season.save() 

सबसे पहले, पंक्तियों (कम से कम psql के अनुसार) डेटाबेस के लिए कभी नहीं जोड़ा गया था। तब मुझे त्रुटि मिली "start_of_season में कोई विशेषता start_season नहीं है" जो अजीब है क्योंकि मैंने कभी भी अपनी स्क्रिप्ट में उस विशेषता को एक्सेस करने का प्रयास नहीं किया है, केवल "start_of_season.start_season_pentad"

तो मैंने सोचा, ठीक है, मैं नाम बदल दूंगा फ़ील्ड का ताकि start_of_season में वह विशेषता हो। और जब मैंने पोस्ट के शीर्ष पर अंश की तरह दिखने के लिए models.py संपादित किया था।

अद्यतन करने models.py अद्यतन करने के बाद,

python manage.py makemigrations 

कोई त्रुटि के साथ भाग गया:

(access_mw)[email protected]:~/dev/access$ python manage.py makemigrations 
Did you rename start_of_season.first_rain_pentad to start_of_season.first_rain (a IntegerField)? [y/N] y 
Did you rename start_of_season.onset_rain_pentad to start_of_season.onset_rain (a IntegerField)? [y/N] y 
Did you rename start_of_season.start_season_pentad to start_of_season.start_season (a IntegerField)? [y/N] y 
Migrations for 'chirps': 
    0010_auto_20150901_1454.py: 
    - Rename field first_rain_pentad on start_of_season to first_rain 
    - Rename field onset_rain_pentad on start_of_season to onset_rain 
    - Rename field start_season_pentad on start_of_season to start_season 

, लेकिन:

python manage.py migrate 

घंटे के लिए यहाँ अटक कर दिया गया है

(access_mw)[email protected]:~/dev/access$ python manage.py migrate 
Operations to perform: 
    Synchronize unmigrated apps: staticfiles, gis, djgeojson, messages, leaflet 
    Apply all migrations: admin, chirps, contenttypes, auth, sessions 
Synchronizing apps without migrations: 
    Creating tables... 
    Running deferred SQL... 
    Installing custom SQL... 
Running migrations: 
    Rendering model states... DONE 
    Applying chirps.0010_auto_20150901_1454... 

मुझे नहीं लगता कि यह इतना लंबा क्यों लेना चाहिए, यह देखते हुए कि वास्तविक तालिका कैसे बनाई गई थी। मुझे यह भी यकीन नहीं है कि मुझे अन्य त्रुटियां क्यों मिल रही थीं। क्या हो रहा है के बारे में कोई विचार?

धन्यवाद

+0

परिवर्तित किए जा रहे तालिकाओं में कितना डेटा है? आपको उस प्रवासन को भी पोस्ट करना चाहिए जिसमें काफी समय लग रहा है। – schillingt

+0

@schillingt psql के अनुसार, तालिका में 0 पंक्तियां बदल दी गई थीं। मैंने "चयन * chirps_start_of_season LIMIT 5 से किया;" तालिका बनाने के बाद और पंक्तियों को जोड़ने का प्रयास करने के बाद, और यह फ़ील्ड नाम, और "0 पंक्तियां" लौटा, जो समस्या # 1 थी। और यही कारण है कि मैं इतनी उलझन में हूं कि माइग्रेशन इस लंबे समय क्यों ले रहा है। आखिरी बार मैंने जांच की थी - अब माइग्रेशन चल रहा है, मैं psql में तालिका को नहीं देख सकता। इसके अलावा, मैं django के लिए नया हूँ। मैं "माइग्रेशन पोस्ट कैसे करूं"? धन्यवाद!! – user20408

+2

आपके पास एक और एसक्यूएल क्लाइंट है जो माइग्रेट किए जा रहे टेबल को पढ़ रहा है। सभी एसक्यूएल क्लाइंट, डीजेंगो गोले बंद करें और फिर से प्रयास करें – e4c5

उत्तर

5

प्रायः एक और एसक्यूएल ग्राहक या Django सर्वर या खोल पढ़ने क्योंकि वहाँ यह है/तालिका जिसे आप संशोधित करना कोशिश कर रहे हैं के लिए लिख।

एक एसक्यूएल कमांड जो स्कीमा को बदलता है उसे तालिका तक पहुंचने पर सफलतापूर्वक निष्पादित नहीं किया जा सकता है। आदर्श रूप से एक त्रुटि संदेश पॉप अप होना चाहिए, लेकिन आमतौर पर ऐसा होता है कि आदेश केवल दूसरों को खत्म करने की प्रतीक्षा करता है।

एक बार जब आप अपने सभी खुले गोले और एसक्यूएल क्लाइंट बंद कर देते हैं, तो स्कीमा परिवर्तन हो सकता है। सबसे बुरे मामले में, आपको साइट को ऑफ़लाइन अस्थायी रूप से ले जाने की आवश्यकता हो सकती है।

+0

यह वास्तव में मेरी समस्या थी। धन्यवाद! – user20408

+0

मदद करने में खुशी हुई – e4c5

संबंधित मुद्दे