You can achieve this in two ways:
1.  python manage.py inspectdb --help
       Introspects the database tables in the given database and outputs a 
Django model module.
       Your id field should be a sequenced integer and  primary key so must 
include these two lines if viewing the CREATE SQL statement
       id integer NOT NULL DEFAULT 
nextval('appname_modelname_id_seq'::regclass) 
       CONSTRAINT ppname_modelname_pkey PRIMARY KEY (id),
2. Review the schema for the table that already has data and manually 
create a django model, make migrations and migrate.
I prefer this method as you get to create the mode the way you want it and 
they way it is best suited for your application.
Generate a create table statement using PGAdmin or any other database 
management tool
Use the create statement as a reference point to create the desired django 
model
Make changes to the table using pgadmin if needed so as to compliment the 
model the way you want it and as you create it
Execute makemigrates and migrate to create the table for this model
Now export the data from your table and use fixtures to import into the 
model

On Friday, December 24, 2021 at 9:23:19 AM UTC-7 matosb...@gmail.com wrote:

> Falar brasileiro?
>
> Em sex., 24 de dez. de 2021 10:03, Sebastian Jung <sebasti...@gmail.com> 
> escreveu:
>
>> Hello,
>>
>> Insectdb is not to generate/update database. Please make it with python 
>> manage.py makemigrations and after that python manage.py migrate
>>
>> Please read a tutorial https://tutorial.djangogirls.org/de/
>>
>> Regards
>>
>> Amor Zamora <amorz...@gmail.com> schrieb am Fr., 24. Dez. 2021, 13:11:
>>
>>> Hi guys. 
>>> I have an application in Django that has a database in postgresql. 
>>> But a new table was added to that database.
>>> I have tried using the inspectdb (python3 manage.py inspectdb 
>>> tracking_visit) command, to add that table to the DJango model, but it 
>>> gives me an exception, it tells me that the ID field of the new table is 
>>> not an integer and if it is, I put it as an integer and primary key and so 
>>> on itself is reflected in the database. 
>>> # Unable to inspect table 'tracking_visit'
>>> # The error was: sequence index must be integer, not 'slice'
>>>
>>> 1. My question is if you know any other method or application that 
>>> allows me to generate the model from the database.
>>> 2. Is there any other way to include changes made from the database into 
>>> the django model?
>>>
>>> Best regards
>>>
>>> -- 
>>> Amor Zamora
>>> Behind the distance, 
>>> your mouth and mine hide, 
>>> complices of a kiss, caresses, fantasies, 
>>> distance as close as the sky and the sea, 
>>> my piece is in your bed, in mine, is your love.
>>> Behind the distance hide love, memories, 
>>> encounters, experiences, circumstances, pain and good times, 
>>> it is after her, the distant ones, 
>>> that we leave feelings, 
>>> but if we really miss, 
>>> distance,
>>> it is only your time.
>>>
>>> -- 
>>> 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.
>>> To view this discussion on the web visit 
>>> https://groups.google.com/d/msgid/django-users/CAKMTbHUWN5QaAyrgrABL5GeKouU0qf2xoxkUqpg-x4WJZmocvg%40mail.gmail.com
>>>  
>>> <https://groups.google.com/d/msgid/django-users/CAKMTbHUWN5QaAyrgrABL5GeKouU0qf2xoxkUqpg-x4WJZmocvg%40mail.gmail.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 django-users...@googlegroups.com.
>>
> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/django-users/CAKGT9myijdck4HQXjKntFrcr-EXDA5Py-By6kJOBkQx43e59Kg%40mail.gmail.com
>>  
>> <https://groups.google.com/d/msgid/django-users/CAKGT9myijdck4HQXjKntFrcr-EXDA5Py-By6kJOBkQx43e59Kg%40mail.gmail.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 django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/845b8b21-923b-4917-9ed7-5120b4360364n%40googlegroups.com.

Reply via email to