in Education by
Issue Recently I came across an issue with a client, that has many solutions, but none was easy. This application uses Postgresql DB and there are two environments: dev and prod. At some point someone thought that it was a good idea to delete one of the tables (module_people_new) from prod without taking care of the FK and other issues that it could carry. Luckily, it was a module that was not very coupled with the application so the application kept working just fine. When I started working with this application, some functions were failing with integrity errors, so I found out it was because of that. I tried the same functions in dev and saw that they were working, so the table was there. Postgresql table description Now, I was wondering if there is a way to "recover" that table in prod, from the information I have in dev. I know that I could just get the table description and built a create query from there, but I was wondering if there is a more "direct" way. With table description I mean: db-> \d+ module_people_new Table "public.module_people_new" Column | Type | Modifiers | Storage | Stats target | Description ---------------------------+--------------------------+-----------+----------+--------------+------------- id | integer | not null | plain | | created_at | timestamp with time zone | not null | plain | | updated_at | timestamp with time zone | not null | plain | | first_name | character varying(255) | not null | extended | | last_name | character varying(255) | not null | extended | | user_id | integer | not null | plain | | . . . Indexes: "module_people_pkey" PRIMARY KEY, btree (id) . . . Check constraints: . . . Foreign-key constraints: "module_user_id_4d9d48da00e81837_fk_module_user_id" FOREIGN KEY (user_id) REFERENCES module_user(id) DEFERRABLE INITIALLY DEFERRED . . . Another possibility The application is a Django app, so I also have the migrations, but I'm afraid there have been a few changes that may have affected that table and others related. But, maybe I could use that. The only problem is that I don't want to copy-paste the migration and simply apply it, cross-finger and hope it works. I know that you can get the SQL query from Django ORM queries, maybe there is a way to get the query from a migration as well? Thanks a lot :) JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
One possibility I could think of is to use inspectdb to inspect the table in dev and output it in a model. python manage.py inspectdb module_people_new > models.py Then generate migrations and create the tables in the production. Then you can create a script to re-populate the table like this: # some_script.py from some_app.models import User # assuming `module_people_new` table's Model Name is ModulePeople for user in User.objects.all(): ModulePeople.objects.get_or_create(user=user, first_name=user.first_name, ...) Then use that script like this: python manage.py shell < some_script.py Or if you want to populate data from database directly from dev, then you can use fixtures. You can dumpdata from dev and use loaddata in production.

Related questions

0 votes
    I need to create JWT token authentication, but I don't know how, could you explain me how to do ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 17, 2022 in Education by JackTerrance
0 votes
    I have a situation where i have a list of primary keys. And i need to filter(OR) a queryset ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 19, 2022 in Education by JackTerrance
0 votes
    I have a situation where i have a list of primary keys. And i need to filter(OR) a queryset ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 19, 2022 in Education by JackTerrance
0 votes
    I have a situation where i have a list of primary keys. And i need to filter(OR) a queryset ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 19, 2022 in Education by JackTerrance
0 votes
    I have the following models: class Project(models.Model): name = models.CharField(max_length=300, unique= ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 22, 2022 in Education by JackTerrance
0 votes
    So in my project, I have a model Chat with many Messages. I want to have ChatSerializer with ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 20, 2022 in Education by JackTerrance
0 votes
    I have a very long forms.py and I'd like to split it to smaller parts with as few as possible ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 4, 2022 in Education by JackTerrance
0 votes
    As a backup for securing your device, it is necessary to create a _____________ (a) backup point (b) ... Need-for-Cyber Security:,Cyber Security-Jobs:,Cyber Security Applications...
asked Nov 1, 2021 in Education by JackTerrance
0 votes
    ________ dump, writes out SQL DDL statements and SQL insert statements to a file, which can then be ... , Database Interview Questions and Answers for Freshers and Experience...
asked Oct 11, 2021 in Education by JackTerrance
0 votes
    Remote backup system must be _________ with the primary site. (a) Synchronised (b) Separated (c) ... Backup Systems topic in chapter Recovery System of Database Management...
asked Oct 11, 2021 in Education by JackTerrance
0 votes
    The simplest way of transferring control is for the old primary to receive __________ from the old backup site ... Systems topic in division Recovery System of Database Management...
asked Oct 10, 2021 in Education by JackTerrance
0 votes
    I am trying to make a API call to wikipedia through: http://en.wikipedia.org/w/api.php?action= ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 21, 2022 in Education by JackTerrance
0 votes
    I am trying to do a poc of Jenkins pipeline as code. I am using the Github organization folder plugin to ... descriptions for the jobs Select the correct answer from above options...
asked Jan 30, 2022 in Education by JackTerrance
0 votes
    I have a table of items with a checkmark disclosure button, and I want to create a second table ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Aug 1, 2022 in Education by JackTerrance
0 votes
    Before starting to enter data in a table, you must create the: a. Design of the table c. Database from which to ... d. All of these Select the correct answer from above options...
asked Dec 31, 2021 in Education by JackTerrance
...