Problem with loaddata fixtures

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Problem with loaddata fixtures

Seba Rossi
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.

--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/d4f31a1d-ea19-48ef-a054-b2bcbe4f8b26%40googlegroups.com.
Reply | Threaded
Open this post in threaded view
|

Re: Problem with loaddata fixtures

Mike Dewhirst-3
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 [hidden email]
> <mailto:[hidden email]>.
> 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>.

--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/43031275-5ca7-556d-87bc-3673f2fca04c%40dewhirst.com.au.