The Model tables in Django got deleted - mysql

The database table created automatically by django from model definition,i kind of deleted it using mysql command line.Now when i'm running a migration it says table doesn't exist .I used makemigrations,syncdb ,nothing works.How do i make django to create that table with those columns again..without me have to creating them manually.

Ok I resolved it, i deleted the migration files from app->migrations folder ,deleted the database from "mysql" .Now i created new migration using "makemigrations" command, and then applied it to my db using "migrate" command.

Related

How to map entity to db already created with Doctrine/Symfony5?

I want to deploy my Symfony5 project on to a remote shared hosting (Hostinger). I've already set up an account on Hostinger and I've also managed to create a database through their database module using "phpMyAdmin".
Now, how can I work with Doctrine if my database is already created and on Hostinger? All the examples I've seen when using Doctrine and Symfony5, create a local database and operate with it. Is it the same steps for a remote database already created?
In my Symfony5 project I've already installed the "symfony/orm-pack" and I've also updated my "DATABASE_URL" on the ".env" file as follows: DATABASE_URL="mysql://u811510647_guillemba:[db_password_hidden_for_obv_reasons]#127.0.0.1:3306/u811510647_containers?serverVersion=10.2"
The parameters of: [db_user, db_password, db_name and serverVersion] are all adapted on what Hostinger's remote database is telling me to enter.
The "symfony console doctrine:database:create" makes no sense if the database is already created no? How can I create an entity on this remote database with Doctrine?
I'd really appreciate some help, thanks a lot!
It sounds like you have an existing database and you want to import the schema to your Symfony project?
php bin/console doctrine:mapping:import "App\Entity" annotation --path=src/Entity
Note: If you want to specify a specific database from your project then you can also pass in the em
--em=myconnectionname

Dropping tables from mysql database after uninstalling the app

I have installed the django-notification-system and again uninstalled this package from my django application then made makeimigration and migrate to put its tables on mysql database.
However after installing, In the project database list I see tables notification_system_notification, notification_system_target_user_record, and notification_system_target , and after uninstalling the package, still these tables remain in the tables' lists. Is there any way to get rid of them without manually dropping/deleting them?
You should migrate your app to zero prior to removing app from INSTALLED_APPS which would effectively remove that app tables from database
As documented
If you want to reverse all migrations applied for an app, use the name
zero:
python manage.py migrate books zero
Once an install/uninstall script has already run, the only way to clear these tables would be to drop them manually or through a script.

Tables not showing in database

I have already migrated the table, then added columns to it. Then again migrated it. But, it says
Nothing to migrate
and, it doesn't even show my table, and it's columns. We three people are working on it and the database is hosted on another server.
When I try to rollback, it shows error:
[ErrorException]
Undefined index: 2017_01_07_071008_create_user_detail_table
And this migration is created by my friend on her computer.
What's the problem here, I don't understand.
Please Help.
You should create another migration to add columns to created table and then run:
composer dumpauto
php artisan migrate
Or you can recreate all tables:
php artisan migrate:refresh
In this case all data will be lost.

how to create migration for already exist table in rails

I have deleted the migration files in rails project. Now i want run the rails project in another system for that i need the migration files to create the table. please tell me how to create the migration files for already created tables in rails.
You still have db/schema.rb file containing all tables and their details..you can use it by rake db:schema:load,this will load the schema into the database, which is faster than running all the migrations.
NEVER DELETE YOUR MIGRATION AND MAINTAIN IT IN SUBVERSION/GIT

rails: changing database

I have created an app using a badly named database, all alterations to important data in the database have been done in fixtures so that I can just drop the database, recreate it and then rake migrate the database tables and fill them with the initial data from the fixtures.
I would like to change the name of my database now, so I updated the database.yml file to reflect another database name. I created the database in mysql and then tried to run the migration and fixtures.
Running the migration with trace shows that it is running commands to create tables etc. However once I am finished I get errors in my application saying that the tables don't exist in the new database.
I go into mysql and check the database and it is completely empty. I have tried wiping everything and running the migrations a few times but nothing changes. Is there something I am missing?
I don't know what commands you used to do the migration, but to migrate a production database (which I infer from the tag, "production-environment"), you have to do:
RAILS_ENV=production rake db:migrate
If that's not the answer, then please provide the command you used to perform the migration, which database you expected to be affected, and the relevant bits of database.yml.