OperationalError, no such column.

OperationalError at /orders/
no such column: orders.customer_id
Request Method: GET
Request URL: http://localhost:9000/orders/
Django Version: 3.1.2
Exception Type: OperationalError
Exception Value:
no such column: orders.customer_id
Exception Location: /Users/xxx/django/db/backends/sqlite3/base.py in execute, line 355
Python Executable: /Users/xxx/Programs/Python/Python38-32
Python Version: 3.8.1

You are trying to add a non-nullable field ‘customer_id’ to snippet without a default;
we can’t do that (the database needs something to populate existing rows).
Please select a fix:
1) Provide a one-off default now (will be set on all existing rows)
2) Quit, and let me add a default in models.py

In Django 1.7, the functionality of an app was integrated directly into Django. When working with migrations, the process is a bit different.
Make changes to models.py as usual.
Create a migration. This generates code to go from the current state to the next state of your model. This is done with the “makemigrations my-app-name” command. This command is smart enough to detect what has changed and will create a script to effect that change to your database.
Next, you apply that migration with “manage.py migrate” command. This command applies all migrations in order.

Step 1: Delete all the migration records from your app’s migration directory. These are files named 0001_,0002_,0003_ etc. Be careful as to not delete the _init__.py file.
Step 2 : Delete the db.sqlite3 file. It will be regenerated later.

Then run the following commands:

$python manage.py makemigrations your-app-name
$python manage.py migrate (new db.sqlite3 will be generated automatically)

Be sure to write the name of your app after makemigrations. You might have to create a superuser to access your database again. Do so by the following:

$python manage.py createsuperuser

Query that returns two character records from MySQL table

Today I will show you how to get records of 2 characters that are mixed in with multiple character records. This particular example I experienced from my work. All 52 states in US each has 2 names: full name and abbreviation name. For example: California is a full name and CA is its abbreviation. However in Canada a state has only full name. For example: Manitoba.

The issue here is that when you have a state table in your database that contains the states of USA and Canada. I will show what query you should use to filter the list of only US States.

Your state table will look like this picture:

The query you will have to use to get only the US states is:

  1. $sql_statement = “Select * from mydb.state_table where CHAR_LENGTH(state_abbr)  = 2”;

And here is the list of states returned by the query above.


Saturday April 3rd from 9:00pm to 11:00pm PST

247Apps Scheduled Maintenance


We will be upgrading our infrastructure improvements to provide greater reliability and performance for our customers.
From 9:00pm to 11:00pm PST, Saturday April 3rd, we will be conducting some hardware upgrades and security patches to our hosting platforms. Services for WordPress Website Builder Elementor, Rental Plugins, Housing Market Analysis, Charts, Custom Calculation, DownloadInsights customers will be affected. While you may continue to work in open applications, you may experience an interruption to web services during the maintenance period.
We apologize for any inconvenience this disruption may cause and thank you for your patience.

Thank you,
247AppsMobi – Web Services of MyNetworkSolution Dev Team

How to view all files in a directory using php.

With PHP version 5.0 and higher, you can apply a function called dir_scan() to return all the filenames in a directory.

$dir    = ‘dir_scan_test/’;
$files1 = scandir($dir);
The list of filenames will be in an array.

With PHP version 4.0 and lower, you have to use opendir($path) function to retrieve a list of files

So, compared to PHP4, applying PHP5 codes will be much cleaner and therefore your scripts will be executed faster.

MySQL Error Code 1215: “Cannot add foreign key constraint”

Why am I unable to create a constraint? The error message doesn’t help much. You just get the following line when you run this SQL statement:

ALTER TABLE user_class ADD FOREIGN KEY (user_id) REFERENCES user(id);

Error Code: 1215
Cannot add foreign key constraint

If you try running some of these SQL statements from mysql ( https://dev.mysql.com/doc/refman/5.6/en/create-table-foreign-keys.html#foreign-keys-adding ), still same error occurred without a reason. You may have to double check a few things within related tables and their fields.

1) The table or index the constraint refers to does not exist yet (usual when loading sql dumps).

2) The table or index in the constraint references misuses quotes.

3) The local key, foreign table or column in the constraint references have a typo.

4) The column the constraint refers to is not of the same type or width as the foreign column

5) The foreign object is not a KEY of any kind

6) The foreign key is a multi-column PK or UK, where the referenced column is not the leftmost one

7) Different charsets/collations among the two table/columns

8) Must be InnoDB

9) Using syntax shorthands to reference the foreign key

10) Using SET DEFAULT for a constraint action