将Webapp2转换为Django后,在谷歌应用引擎上使用现有的NDB

时间:2021-10-18 23:14:19

I am in the process of converting a Webapp2 app to Django on Google App Engine. Everything is relatively straightforward, and the models have been converted from the webapp models to the django equivalents.

我正在谷歌app Engine将Webapp2应用程序转换为Django。一切都相对简单,模型已经从webapp模型转换为django模型。

However, I feel this may be have been glossed over in the posts from the app engine team Refering This... Do I need to perform a data migration in order to re-use existing data, or can I simply use the existing NDB models somehow? (If so, what configurations are needed? I can't seem to figure this out).

然而,我觉得这可能已经被应用引擎团队的帖子掩盖了……我是否需要执行数据迁移以重用现有数据,或者我是否可以简单地以某种方式使用现有的NDB模型?(如果需要,需要什么配置?)我似乎搞不清楚)。

2 个解决方案

#1


1  

there is no concept of a data migration in schemaless databases. A migration that you think of is really creation or alteration of a database schema i.e the DB needs to have a schema only then would the idea of a migration make sense.

无模式数据库中没有数据迁移的概念。您认为的迁移实际上是创建或更改数据库模式i。DB需要有一个模式,只有这样迁移的想法才有意义。

#2


0  

After looking into this a little further, I noticed that by default GAE would create db_tables with the default names as <app_label>_<model_name> (i.e. coreapp_GuestBook).

在进一步研究这个问题之后,我注意到默认情况下,GAE将创建具有默认名称为 _ (即coreapp_GuestBook)的db_tables。

As a result, if you specify the model meta options in Django, matching the converted apps name with the original apps name, you will be able to access the same models with Django. Note that the field values may be inaccessible or possible corrupted if you did not do the conversion of webapp fields to the appropriate Django fields one for one.

因此,如果您在Django中指定模型元选项,将转换后的应用程序名称与原始应用程序名称匹配,您将能够使用Django访问相同的模型。注意,如果不将webapp字段转换为适当的Django字段,则字段值可能无法访问或可能被破坏。

See reference: https://cloud.google.com/appengine/articles/django-nonrel

见参考:https://cloud.google.com/appengine/articles/django-nonrel

For example, in my case, the Article app would be retrieved by specifying:

例如,在我的例子中,通过指定:

class Article(models.Model):
    title = models.CharField(max_length=255)

    class Meta:
        db_table = 'Article'
        verbose_name = 'Article'
        verbose_name_plural = 'Articles'

#1


1  

there is no concept of a data migration in schemaless databases. A migration that you think of is really creation or alteration of a database schema i.e the DB needs to have a schema only then would the idea of a migration make sense.

无模式数据库中没有数据迁移的概念。您认为的迁移实际上是创建或更改数据库模式i。DB需要有一个模式,只有这样迁移的想法才有意义。

#2


0  

After looking into this a little further, I noticed that by default GAE would create db_tables with the default names as <app_label>_<model_name> (i.e. coreapp_GuestBook).

在进一步研究这个问题之后,我注意到默认情况下,GAE将创建具有默认名称为 _ (即coreapp_GuestBook)的db_tables。

As a result, if you specify the model meta options in Django, matching the converted apps name with the original apps name, you will be able to access the same models with Django. Note that the field values may be inaccessible or possible corrupted if you did not do the conversion of webapp fields to the appropriate Django fields one for one.

因此,如果您在Django中指定模型元选项,将转换后的应用程序名称与原始应用程序名称匹配,您将能够使用Django访问相同的模型。注意,如果不将webapp字段转换为适当的Django字段,则字段值可能无法访问或可能被破坏。

See reference: https://cloud.google.com/appengine/articles/django-nonrel

见参考:https://cloud.google.com/appengine/articles/django-nonrel

For example, in my case, the Article app would be retrieved by specifying:

例如,在我的例子中,通过指定:

class Article(models.Model):
    title = models.CharField(max_length=255)

    class Meta:
        db_table = 'Article'
        verbose_name = 'Article'
        verbose_name_plural = 'Articles'