zoukankan      html  css  js  c++  java
  • django 数据库迁移成功 但是表没有创建

    花了接近一上午的时间,终于解决了。

    """
    执行完python manage.py makemigrations;python manage.py migrate;
    两条命令,没有报错,分别显示如下:
    python manage.py makemigrations:
    
    Migrations for 'algofilter':
      migrations001_initial.py
        - Create model T15Min
        - Create model T1Day
        - Create model T1Min
        - Create model T30Min
        - Create model T5Min
        - Create model TAlgoFilter
        - Create model TAlgoindicators
        - Create model TAlgoinfo
        - Create model TAlgoInvoke
        - Create model TAlgolab
        - Create model TAlgolabcor
        - Create model TSysparam
        - Create model TUniverse
    Migrations for 'hisback':
      C:UsersASUSDesktopweizhongwzapihisbackmigrations001_initial.py
        - Create model TOptim
        - Create model TOptimdetail
        - Create model TSim
        - Create model TSimrun
    Migrations for 'universe':
      C:UsersASUSDesktopweizhongwzapiuniversemigrations001_initial.py
        - Create model TUniverse
        - Create model TUniversedetail
        
        
    python manage.py migrate:
    
     Applying contenttypes.0001_initial... OK
      Applying auth.0001_initial... OK
      Applying admin.0001_initial... OK
      Applying admin.0002_logentry_remove_auto_add... OK
      Applying algofilter.0001_initial... OK
      Applying contenttypes.0002_remove_content_type_name... OK
      Applying auth.0002_alter_permission_name_max_length... OK
      Applying auth.0003_alter_user_email_max_length... OK
      Applying auth.0004_alter_user_username_opts... OK
      Applying auth.0005_alter_user_last_login_null... OK
      Applying auth.0006_require_contenttypes_0002... OK
      Applying auth.0007_alter_validators_add_error_messages... OK
      Applying auth.0008_alter_user_username_max_length... OK
      Applying auth.0009_alter_user_last_name_max_length... OK
      Applying hisback.0001_initial... OK
      Applying sessions.0001_initial... OK
      Applying universe.0001_initial... OK
    """
    
    
    """
    但是数据库只存在django内置的几张表,其他的app里面的model表没有新建,查了很多答案,但是都没有成功,总结如下:
    
    1.可能是app名没有注册到setting.py的install_app中
    2.执行迁移命令时加上app名称,python manage.py migrations appname
    """
    
    
    """
    最终把这个问题翻译成英文,在stackoverflow上搜到了答案:
    
    数据model是我在公司通过数据库反向生成的,所以在class Meta 类中会有字段managed=False, 官方文档对这个字段的解释是"If False, no database table creation or deletion operations will be performed for this model.",之前建立视图也是将这个字段改为False,
    所以在迁移到另一个数据库的时候不会生成表,于是将managed设置为True就完美解决了这个问题。
    """
    
  • 相关阅读:
    【项目】项目75
    【项目】项目74
    【项目】项目73
    【项目】项目72
    【项目】项目71
    【项目】项目70
    【项目】项目69
    【项目】项目68
    【项目】项目67
    .Net随笔:解决VS2008,重新生成解决方案,很慢
  • 原文地址:https://www.cnblogs.com/michealjy/p/14018517.html
Copyright © 2011-2022 走看看