django main.app_table__old Error deleting item - sql

I am facing this problem and I tried many solutions but no one works for me or it is not convinient of my case.
First I use Django==2.0 (can't change to version due to problems).
I have I model table named table and my app is appwhen developing it happend that I can't delete any element in that table (the other works fine). and I get this problem.
OperationalError at /fieldsdetails/25/delete/
no such table: main.app_table__old
I tried to delete all migrations history so the db.sqlite3 and run:
python manage.py makemigrations
python manage.py migrate
Then I tried to delete the table as
python manage.py dbshell
SELECT * FROM sqlite_master WHERE type='table';
then I found a table named app_table__old and deleting it using this:
DROP TABLE app_table__old
.exit
but nothing works?
is there any solution I don't want to upgrade Django version or lose data.

I just discovered a tricky way to solve this without losing or changing or upgrading Django.
The problem happens when the sqlite lost some information in the data base.
To solve the problem follow those steps:
1- go to your models tables and search for other tables that have ForeignKey or any relation to the table for example:
class table_Perimeter(models.Model):
Perimeter = models.ForeignKey( table, on_delete=models.CASCADE)
then when you define all tables that have relation with table. you need to fix the problem in the database itself db.sqlite3.
install the SQLiteStudio browser from this site https://sqlitestudio.pl/
then go to table_Perimeter and double click on it. you will see something like this.
double click to re-configuration ForeignKey and you will see a red icon:
Here enter to configure it again
from this window select the foreig table and Foreig id and click apply
click to commit the changes
So everything will work perfectly just run your server :)

Related

How can I run a specific migration in Symfony 5 for my mysql database?

Hi every body I'm learning Symfony 5, on migrations lessons, after a lot of make:migration commands, this time I've this messageenter image description here
And on doctrine:migrations:migrate command, I've this error
enter image description here
But in my migrations file , there's a migration with create etudiant table.
So I'll know how to run that one migration for having that table in my database, Thanks!
This Error often happened when you got some differents between the last migration file and your BDD.
First of all your script seems to drop 'etudiant' table but this one does not exist. May be you have drop it before.
However you have many possibility :
You can delete all migration file on your symfony project (under migrations folder), then delete all sql entry on doctrine_migration_versions.
After that you can redo your migration command line (make:migration and doctrine:migrations:migrate).
You can edit the last migration file on your symfony projet and delete the drop table in trouble.

error loading table on bigquery dashboard but queries works fine

I clicked a table on bigquery dashboard, got this error:
However, I can get data when I do a select on this table. (That means the table does exist)
I already have the highest admin privilege so it shouldn't be a permission issue.
I created this table with python script, which collects data, writes into a csv file, and upload the csv file to bigquery everyday. After I created the table I once changed the schema both in the script and on the dashboard. Not sure if that's the cause, but the table loading error occurred several days after I changed the schema.
If you have Addblock extensions, this might be the root cause of this issue. Thus, try disabling it, then try running your query again.
Hope it helps.

Crate db cannot query data in a shard

I have a instance of Crate 1.0.2 and I dropped a table from it. Then re-created table with same name and slightly modified schema. Then I imported data using copy from command. File argument to copy from command consists of 10,000 records and copy from command runs ok. When I check table tab in crate web console, it shows many partitions added and each partition having few records. If I add number of records column on this tab, it comes close to 10k but when I fire a command "select count(*) from mytable", it returns around 8000 records only. On further investigation found that there are certain partitions on which data cannot be queried at all. Has any one seen this problem? Does it have anything to do with table drop and creation with same name ? I also observed that when a table is dropped, not all files related to that table are deleted from path.data. Are these directories a reason for those partitions become non-query able? While importing, I saw "Document already exists" exception. I know my data does not have any duplicate value for primary column.
Some questions to clarify the issue:
Have you run refresh table mytable after your copy command has finished?
Are you sure that with the new schema of the table, there are no duplicate records?
Since 1.x versions are not supported anymore, could you try with CrateDB 2.1.6 which is the current stable version to see if the problem persists?

Controlling the updates in my Database

I came here today to see if someone could give me a suggestion to improve the way I update my database.
Here is the problem, I have one file that I store new scripts every time that I need to change something. For instance, let's say I need to add a new column in a table. I would add the following line in my file called script1.sql:
alter table CLIENTS
add AGE integer
After doing that, I am going to send it to a client with an updated application, and ask him to run script1.sql on his database. That works just fine for me.
The problem shows up when this file starts to get bigger, and the client needs to receive the new updates.
The client would run the script1.sql file again, but now with more updates. He will get errors indicating that a column named AGE already exists in the database.
The biggest problem is when I change the version of my application. If I update my application from Application1 to Application2, I also change the script from script1.sql to script2.sql.
Now, my client will need to run both to get to the correct version without conflicts. He will also get lots of errors, since almost everything from script1.sql was already processed in his database.
What I want is to eliminate the chance to face conflicts. This process has been working for me, but always causing some sort of trouble. Therefore, if anyone has any idea about how I could make it work better, please help me out.
Usually SQL provides something called IF EXISTS ( also IF NOT EXISTS) so eg you can write a statement such as:
CREATE TABLE IF NOT EXISTS users ...
Which will only create the users table if it hasn't already been created.
There is usually a variant of this that can be added to all your statements (including updates such as renaming columns etc).
Then if the table has already been added (or column updated etc) then it won't try to run that SQL command again - which means you can run the same file over and over as many times as you like.
(Note: this is called idempotency)
You will need to google for the details on how to use EXISTS for sql-server

Adding a migration in the middle of previous migrations safe?

I have a minor issue which force me to introduce a new migration in between two migrations.
Short version of my question is: whether it is safe to introduce a new migration between previous two.
What I did
I need to have a table which will be filled from a file.
I added a table then imported data on the table by two migrations:
A migration which create a table with named ID column by using self.primary_key = some_id
A migration to import text data onto the table
The issue was, I forgot to add :id => false to the first migration. This cause id column to be created but haven't set correctly. Since I have primary key in some_id it does not cause problem up to now.
Rails 3.2.4
Now, I upgraded to Rails 3.2.4. Due to the change, it look like I need to set unique id before save. Which cause migration 2 above to fail.
The easiest fix is removing id column between above two migrations because I need test suite to build the database from scratch time to time. To make the import to work, I need to fix it before 2nd migration run.
Question
Now the question.
Since above migrations are deployed already, The migration will run after all of the migrations other than the one.
In my case, it looks like Ok to create such a migration (with timestamp in between above two).
Is it okay to do add migration like this way, in this case?