Problem with loaddata fixtures

瀏覽次數:12 次
跳到第一則未讀訊息

Seba Rossi

未讀,
2019年10月18日 下午1:45:552019/10/18
收件者:Django users
Hello there i was trying to migrate my database from SQLite to PostgreSQL following the docs steps but it seems that i encountered a problem wich i can't resolve.

I have a base model called Producto wich has no dependencies.

I have another model called Preaprobado that has the following field:

    productos = models.ManyToManyField(Producto, related_name = "preaprobados", default = Producto.objects.get(CMS_id = 1))


The thing is that in order for the app to work i need one mandatory Product with CMS_id field = 1.

I managed to dumpdata from every model separatedly succesfully, then i changed the DB config in settings.py and was able to run the migrate command succesfully.

The problem is that when i try to loaddata InitialProducts.json the console returns an error displaying that the query 
Producto.objects.get(CMS_id = 1)
has no value.

I tried disabling the signals as it says in the loaddata docs but honestly i don't know where should i add the code disabling the signals since the error is raised when defining the models.py

Any help is more than welcomed.

Mike Dewhirst

未讀,
2019年10月18日 晚上8:56:552019/10/18
收件者:django...@googlegroups.com
On 19/10/2019 1:37 am, Seba Rossi wrote:
> Hello there i was trying to migrate my database from SQLite to
> PostgreSQL following the docs steps but it seems that i encountered a
> problem wich i can't resolve.

I think dumpdata and loaddata  are for fixtures used in unit tests and
not for migrating between databases.

You need to look at the SQLite docs and the PostgreSQL docs for dumping
and reloading between them.

The nice thing is you can edit the SQL dump file before reloading in the
other database if you need to be clever.

Mike

>
> I have a base model called Producto wich has no dependencies.
>
> I have another model called Preaprobado that has the following field:
>
> |
>     productos = models.ManyToManyField(Producto, related_name =
> "preaprobados", default = Producto.objects.get(CMS_id = 1))
>
> |
>
> The thing is that in order for the app to work i need one mandatory
> Product with CMS_id field = 1.
>
> I managed to dumpdata from every model separatedly succesfully, then i
> changed the DB config in settings.py and was able to run the migrate
> command succesfully.
>
> The problem is that when i try to loaddata InitialProducts.json the
> console returns an error displaying that the query
> |
> Producto.objects.get(CMS_id = 1)
> |
> has no value.
>
> I tried disabling the signals as it says in the loaddata docs
> <https://docs.djangoproject.com/es/2.2/ref/django-admin/#loaddata> but
> honestly i don't know where should i add the code disabling the
> signals since the error is raised when defining the models.py
>
> Any help is more than welcomed.
> --
> You received this message because you are subscribed to the Google
> Groups "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to django-users...@googlegroups.com
> <mailto:django-users...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/d4f31a1d-ea19-48ef-a054-b2bcbe4f8b26%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/d4f31a1d-ea19-48ef-a054-b2bcbe4f8b26%40googlegroups.com?utm_medium=email&utm_source=footer>.

回覆所有人
回覆作者
轉寄
0 則新訊息