Altering database tables in Django

前端 未结 7 1384
野性不改
野性不改 2020-12-07 11:33

I\'m considering using Django for a project I\'m starting (fyi, a browser-based game) and one of the features I\'m liking the most is using syncdb to automatica

7条回答
  •  生来不讨喜
    2020-12-07 11:57

    I've been using django-evolution. Caveats include:

    • Its automatic suggestions have been uniformly rotten; and
    • Its fingerprint function returns different values for the same database on different platforms.

    That said, I find the custom schema_evolution.py approach handy. To work around the fingerprint problem, I suggest code like:

    BEFORE = 'fv1:-436177719' # first fingerprint
    BEFORE64 = 'fv1:-108578349625146375' # same, but on 64-bit Linux
    AFTER = 'fv1:-2132605944' 
    AFTER64 = 'fv1:-3559032165562222486'
    
    fingerprints = [
        BEFORE, AFTER,
        BEFORE64, AFTER64,
        ]
    
    CHANGESQL = """
        /* put your SQL code to make the changes here */
        """
    
    evolutions = [
        ((BEFORE, AFTER), CHANGESQL),
        ((BEFORE64, AFTER64), CHANGESQL)
        ]
    

    If I had more fingerprints and changes, I'd re-factor it. Until then, making it cleaner would be stealing development time from something else.

    EDIT: Given that I'm manually constructing my changes anyway, I'll try dmigrations next time.

提交回复
热议问题